﻿using System;
using System.Collections.Generic;
using System.CodeDom;

namespace MaoCaiJun.DataBase.BuildProviders.Function
{
    class CatalogSqlite
    {
        #region 字段
        public static MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property ID
        {
            get
            {
                return new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "栏目id", Name = "Id", SqlName = "Id", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = true, SqlLength = "255", SqlIndex = "PK_" + System.Guid.NewGuid().ToString("N") };
            }
        }
        public static MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property[] Property
        {
            get
            {
                List<MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property> _property = new List<MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property>();
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "根栏目ID", Name = "rootID", SqlName = "RootID", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "父栏目ID", Name = "ParentID", SqlName = "ParentID", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Public });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "同级的上一个栏目ID", Name = "prevID", SqlName = "PrevID", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "同级的下一个栏目ID", Name = "nextID", SqlName = "NextID", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "栏目层数", Name = "depth", SqlName = "Depth", Value = "0", SqlValue = "0", Type = "System.Int32", SqlType = "int", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "子栏目数", Name = "Child", SqlName = "Child", Value = "0", SqlValue = "0", Type = "System.Int32", SqlType = "int", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Public });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "排序ID", Name = "orderID", SqlName = "OrderID", Value = "0", SqlValue = "0", Type = "System.Int32", SqlType = "int", SqlNotNull = false, SqlLength = "255", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                _property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "栏目路径", Name = "parentPath", SqlName = "ParentPath", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "MAX", SqlIndex = "", Attribute = MemberAttributes.Assembly });
                //_property.Add(new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property { Summary = "名称", Name = "title", SqlName = "title", Value = "", SqlValue = "", Type = "System.String", SqlType = "nvarchar", SqlNotNull = false, SqlLength = "MAX", SqlIndex = "", Attribute = MemberAttributes.Assembly });

                return _property.ToArray();
            }
        }
        #endregion 字段

        public CatalogSqlite(MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class dbsAnalysisClass)
        {

            dbsAnalysisClass.ID = Function.Catalog.ID;
            dbsAnalysisClass.Property.AddRange(Function.Catalog.Property);
            //-----------------------

            List<MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property> _modelField = new List<MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property>();
            _modelField.Add(dbsAnalysisClass.ID);
            _modelField.AddRange(dbsAnalysisClass.Property);
        
            ////////////////////////////////////////////////////////////
            #region  Catalog

            #region 生成类
            CodeTypeDeclaration ctd1 = new CodeTypeDeclaration(dbsAnalysisClass.Name);//生成类
            ctd1.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctd1.Comments.Add(new CodeCommentStatement(" Copyright (C) " + DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 文件功能描述：  无限分类 " + dbsAnalysisClass.Name + "的逻辑体", false));
            ctd1.Comments.Add(new CodeCommentStatement("", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctd1.Comments.Add(new CodeCommentStatement("", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd1.Comments.Add(new CodeCommentStatement("", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd1.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd1.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            ctd1.IsClass = true;
            ctd1.IsPartial = true;
            ctd1.Attributes = MemberAttributes.Public;
            //生成类注释
            ctd1.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctd1.Comments.Add(new CodeCommentStatement("无限分类 " + dbsAnalysisClass.Name + "的逻辑体", true));
            ctd1.Comments.Add(new CodeCommentStatement("</summary>", true));
            #endregion

            #region 生成类字段
            CodeMemberField fieldShowLine = new CodeMemberField();
            fieldShowLine.Attributes = MemberAttributes.Private | MemberAttributes.Static;
            fieldShowLine.Type = new CodeTypeReference(typeof(System.Collections.ArrayList));
            fieldShowLine.Name = "showLine = new System.Collections.ArrayList(new bool[]{ false, false, false, false, false, false, false, false, false, false })";
            ctd1.Members.Add(fieldShowLine);

            CodeMemberField fieldnbsp = new CodeMemberField();
            fieldnbsp.Attributes = MemberAttributes.Private | MemberAttributes.Static;
            fieldnbsp.Type = new CodeTypeReference(typeof(string));
            fieldnbsp.Name = "nbsp = new string(new char[] { (char)0xA0 })";
            ctd1.Members.Add(fieldnbsp);
            #endregion

            #region 属性
            //生成类的字段注释 和 私有字段
            
            //CodeMemberField cmf = new CodeMemberField();
            //cmf.Comments.Add(new CodeCommentStatement("<summary>", true));
            //cmf.Comments.Add(new CodeCommentStatement("父栏目", true));
            //cmf.Comments.Add(new CodeCommentStatement("</summary>", true));
            //cmf.Attributes = MemberAttributes.Private;
            //cmf.Type = new CodeTypeReference(dbsAnalysisClass.Name);
            //if (string.IsNullOrEmpty(daf.Value))
            //{
            //    if (daf.Type == "System.String")
            //    {
            //        cmf.Name = "_" + daf.Name.ToLower() + " = string.Empty";
            //    }
            //    else
            //    {
            //        cmf.Name = "_" + daf.Name.ToLower() + " = new " + daf.Type + "()";
            //    }
            //}
            //else
            //{

            //    cmf.Name = "_" + daf.Name.ToLower() + " = " + daf.Type.Replace("System.", "System.Convert.To") + "(\"" + daf.Value + "\")";

            //}

            ////生成类的属性注释 和 属性
            //CodeMemberProperty cmp = new CodeMemberProperty();
            //cmp.Comments.Add(new CodeCommentStatement("<summary>", true));
            //cmp.Comments.Add(new CodeCommentStatement(daf.Summary, true));
            //cmp.Comments.Add(new CodeCommentStatement("</summary>", true));
            //cmp.Attributes = daf.Attribute;
            //cmp.Type = new CodeTypeReference(daf.Type);
            //cmp.Name = daf.Name;
            //cmp.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + daf.Name.ToLower())));
            //cmp.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + daf.Name.ToLower()), new CodePropertySetValueReferenceExpression()));

            //ctd.Members.Add(cmf);
            //ctd.Members.Add(cmp);
            #endregion 属性

            ReturnType(ctd1);

            #region 方法
            ////filtrate
            //CodeMemberMethod methodFiltrate = new CodeMemberMethod();
            //methodFiltrate.Comments.Add(new CodeCommentStatement("<summary>", true));
            //methodFiltrate.Comments.Add(new CodeCommentStatement("过滤特殊字符", true));
            //methodFiltrate.Comments.Add(new CodeCommentStatement("</summary>", true));
            //methodFiltrate.Comments.Add(new CodeCommentStatement("<param name=\"sqlstr\">要过滤特殊字符的字符串</param>", true));
            //methodFiltrate.Comments.Add(new CodeCommentStatement("<returns>过滤好的字符串</returns>", true));
            //methodFiltrate.Name = "filtrate";
            //methodFiltrate.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //methodFiltrate.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "sqlstr"));
            //methodFiltrate.ReturnType = new CodeTypeReference(typeof(string));
            //methodFiltrate.Statements.Add(new CodeSnippetExpression("sqlstr = sqlstr.Replace(\"'\", \"''\")"));
            //methodFiltrate.Statements.Add(new CodeSnippetExpression("sqlstr = sqlstr.Replace(\"--\", \"\")"));
            //methodFiltrate.Statements.Add(new CodeSnippetExpression("sqlstr = sqlstr.Replace(\":\", \"\")"));
            //methodFiltrate.Statements.Add(new CodeSnippetExpression("return sqlstr"));
            //ctd1.Members.Add(methodFiltrate);
//            //SearchCatalog
//            CodeMemberMethod methodSelectCatalog = new CodeMemberMethod();
//            methodSelectCatalog.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodSelectCatalog.Comments.Add(new CodeCommentStatement("得到一个对象实体", true));
//            methodSelectCatalog.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodSelectCatalog.Comments.Add(new CodeCommentStatement("<param name=\"className\">栏目名称</param>", true));
//            methodSelectCatalog.Comments.Add(new CodeCommentStatement("<returns> </returns>", true));
//            methodSelectCatalog.Name = "Search" + dbsAnalysisClass.Name;
//            methodSelectCatalog.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodSelectCatalog.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
//            methodSelectCatalog.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name);
            string strTemp = @"
            System.Collections.Generic.List<{0}> lc = Select{0}(0, 1, ""className = '"" + className + ""'"", ""OrderID"");
            return lc.Count > 0 ? lc[0] : null;
";
//            methodSelectCatalog.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
//            ctd1.Members.Add(methodSelectCatalog);
            #region 添加栏目1
            //AddCatalog1
            CodeMemberMethod methodAddClass1 = new CodeMemberMethod();
            methodAddClass1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodAddClass1.Comments.Add(new CodeCommentStatement("添加栏目", true));
            methodAddClass1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodAddClass1.Comments.Add(new CodeCommentStatement("<param name=\"item\">要添加的对像</param>", true));
            methodAddClass1.Comments.Add(new CodeCommentStatement("<param name=\"parentItem\">父栏目</param>", true));
            methodAddClass1.Comments.Add(new CodeCommentStatement("<returns>状态</returns>", true));
            methodAddClass1.Name = "Add" + dbsAnalysisClass.Name;
            methodAddClass1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodAddClass1.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "item"));
            methodAddClass1.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "parentItem"));
            methodAddClass1.ReturnType = new CodeTypeReference("ReturnType");
            methodAddClass1.Statements.Add(new CodeSnippetExpression("return Add" + dbsAnalysisClass.Name+"(item, parentItem == null ? \"\" : parentItem.Id)"));
            ctd1.Members.Add(methodAddClass1);
            #endregion 添加栏目1
            #region 添加栏目2
            //AddCatalog2
            CodeMemberMethod methodAddClass2 = new CodeMemberMethod();
            methodAddClass2.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodAddClass2.Comments.Add(new CodeCommentStatement("添加栏目", true));
            methodAddClass2.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodAddClass2.Comments.Add(new CodeCommentStatement("<param name=\"item\">要添加的对像</param>", true));
            methodAddClass2.Comments.Add(new CodeCommentStatement("<param name=\"ParentID\">父栏目id</param>", true));
            methodAddClass2.Comments.Add(new CodeCommentStatement("<returns>状态</returns>", true));
            methodAddClass2.Name = "Add" + dbsAnalysisClass.Name;
            methodAddClass2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodAddClass2.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "item"));
            methodAddClass2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ParentID"));
            methodAddClass2.ReturnType = new CodeTypeReference("ReturnType");

            strTemp = @"
            ReturnType rt=ReturnType.Err;
            {0} parent{0} = null;
            {0} max{0} = null;
            string sql = string.Empty;
            #region 检查是不是有重复的ID
            sql = ""Select id From ["" + TableName + ""] Where [id]='"" + item.Id + ""'"";
            if ({0}.Database.ExecuteScalar(sql) != null)
            {{
                //表示有重复的项目ID
                return ReturnType.Repeat;
            }}
            #endregion 检查是不是有重复的ID

            #region 如果父类不为空，则检查父类是否存在，并给父类赐值
            if (!string.IsNullOrEmpty(ParentID))
            {{
                parent{0} = {0}.Get{0}(ParentID);
                if (parent{0} == null)
                {{
                    //表示父类不存在
                    return ReturnType.NoParent;
                }}
                else
                {{
                    //存在父类
                    item.ParentID = ParentID;//重新定义ParentID
                    item.parentPath = parent{0}.parentPath + "","" + item.ParentID;//重新定义parentPath
                    item.depth = parent{0}.depth + 1;//重新定义depth
                    item.orderID = parent{0}.orderID + 1;//重新定义orderID
                    item.rootID=parent{0}.rootID;
                    parent{0}.Child += 1;//父栏目的Child+1
                }}
            }}
            else
            {{
                //为顶级项，不存在父类
                item.ParentID = """";//重新定义ParentID
                item.rootID = item.Id;//重新定义rootID
                item.parentPath = "","";//重新定义parentPath
                item.depth = 0;//重新定义depth
            }}
            #endregion 如果父类不为空，则检查父类是否存在

            #region 查找当前栏目的最大的orderID
            System.Collections.Generic.List<{0}> tmp = {0}.Select{0}(1, 1, ""[ParentID]='"" + ParentID + ""'"", ""[orderID] desc"");
            if (tmp.Count == 0)
            {{
               //当前栏目不存在其它项
               item.prevID = """";//重新定义prevID
               item.nextID = """";//重新定义nextID
            }}
            else
            {{
                max{0} = tmp[0];
               //重新定义同一级栏目上一级的nextID
               max{0}.nextID = item.Id;

               item.prevID = tmp[0].Id;//重新定义prevID
               item.nextID = """";//重新定义nextID
               item.orderID = tmp[0].orderID + 1;//orderIDnextID
            }}
            #endregion 查找当前栏目的最大的orderID


            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                #region 重新修改其他栏目的orderID
                sql = ""update ["" + TableName + ""] set [orderID]=[orderID]+1 where [orderID]>="" + item.orderID;
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text, sql);
                #endregion 重新修改其他栏目的orderID
                #region 保存
                if (parent{0} != null) {{ parent{0}.Update(dTran); }}
                if (max{0} != null) {{ max{0}.Update(dTran); }}
                item.Save(dTran);
                #endregion 保存
                dTran.Commit();
                rt= ReturnType.OK;
            }}
            catch (Exception)
            {{

                rt= ReturnType.Err;
            }}
            finally
            {{
                dConn.Close();
            }}
            return rt;
";
            methodAddClass2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodAddClass2);
            #endregion 添加栏目
            #region 修改栏目1
            //////ModifyClass1
            ////CodeMemberMethod methodModifyClass1 = new CodeMemberMethod();
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("<summary>", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("修改栏目", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("</summary>", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("<param name=\"id\">要修改栏目ID</param>", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("<param name=\"classname\">栏目名称</param>", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("<param name=\"description\">栏目详情</param>", true));
            ////methodModifyClass1.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:栏目不存在 2:同一级栏目已经有重复的</returns>", true));
            ////methodModifyClass1.Name = "Modify" + dbsAnalysisClass.Name;
            ////methodModifyClass1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            ////methodModifyClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Int32), "id"));
            ////methodModifyClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "classname"));
            ////methodModifyClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "description"));
            ////methodModifyClass1.ReturnType = new CodeTypeReference(typeof(Int32));
            ////methodModifyClass1.Statements.Add(new CodeSnippetExpression(dbsAnalysisClass.Name + " temp=new " + dbsAnalysisClass.Name + "()"));
            ////methodModifyClass1.Statements.Add(new CodeSnippetExpression("temp.Id=id"));
            ////methodModifyClass1.Statements.Add(new CodeSnippetExpression("temp.ClassName=classname"));
            ////methodModifyClass1.Statements.Add(new CodeSnippetExpression("temp.Description=description"));
            ////methodModifyClass1.Statements.Add(new CodeSnippetExpression("return MoveClass(temp)"));
            ////ctd1.Members.Add(methodModifyClass1);
            #endregion 修改栏目1
            #region 修改栏目2
            //ModifyClass2
            CodeMemberMethod methodModifyClass2 = new CodeMemberMethod();
            methodModifyClass2.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodModifyClass2.Comments.Add(new CodeCommentStatement("修改栏目", true));
            methodModifyClass2.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodModifyClass2.Comments.Add(new CodeCommentStatement("<param name=\"item\">要修改的栏目对像</param>", true));
            methodModifyClass2.Comments.Add(new CodeCommentStatement("<returns>状态</returns>", true));
            methodModifyClass2.Name = "Modify" + dbsAnalysisClass.Name;
            methodModifyClass2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodModifyClass2.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "item"));
            methodModifyClass2.ReturnType = new CodeTypeReference("ReturnType");

            strTemp = @"
            {0} temp = new {0}();
            if (!temp.Read(item.Id))
            {{
                return ReturnType.NoItem;//栏目不存在
            }}
            item.Child = temp.Child;
            item.depth = temp.depth;
            item.Id = temp.Id;
            item.nextID = temp.nextID;
            item.orderID = temp.orderID;
            item.ParentID = temp.ParentID;
            item.parentPath = temp.parentPath;
            item.prevID = temp.prevID;
            item.rootID = temp.rootID;
//            if ({0}.Select{0}Count(""[classname]='"" + item.ClassName.Replace(""'"",""''"") + ""' and [parentid]="" + item.ParentID + "" and [id]<>"" + item.Id) != 0)
//            {{
//                return 2;//同一级栏目已经有重复的
//            }}

            return item.Update() ? ReturnType.OK : ReturnType.Err;";
            methodModifyClass2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodModifyClass2);
            #endregion 修改栏目
            #region 删除栏目1
            //deleteTree1
            CodeMemberMethod methodDeleteTree1 = new CodeMemberMethod();
            methodDeleteTree1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodDeleteTree1.Comments.Add(new CodeCommentStatement("删除栏目树", true));
            methodDeleteTree1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodDeleteTree1.Comments.Add(new CodeCommentStatement("<param name=\"id\">要删除栏目ID</param>", true));
            methodDeleteTree1.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:栏目不存在 </returns>", true));
            methodDeleteTree1.Name = "Delete" + dbsAnalysisClass.Name + "AndChildren";
            methodDeleteTree1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodDeleteTree1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodDeleteTree1.ReturnType = new CodeTypeReference("ReturnType");
            strTemp = @"
            ReturnType rt=ReturnType.Err;
            {0} ug = {0}.Get{0}(id);
            if (ug == null)
            {{
                return ReturnType.NoItem;//栏目不存在
            }}


            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                if (ug.depth > 0)
                //更新父系栏目的子栏目数目
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [Child]=[Child]-1 where [id]='"" + ug.ParentID + ""'"");

                //修改上一类别的NextID和下一类别的PrevID
                if (!string.IsNullOrEmpty(ug.prevID))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [NextID]='"" + ug.nextID + ""' where [id]='"" + ug.prevID + ""'"");
                if (!string.IsNullOrEmpty(ug.nextID))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [PrevID]='"" + ug.prevID + ""' where [id]='"" + ug.nextID + ""'"");
                //删除这个栏目
                string sql = ""delete from ["" + TableName + ""] where [id]='"" + id + ""'"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);

                int orderid=0;
                if (ug.Child > 0)
                {{
                    string children = GetChildren(id);
                    //得到最大的orderid,以便后面更新orderid
                    sql = ""select max(orderid) from ["" + TableName + ""] where [id] in ('"" + children.Replace("","",""','"") + ""')"";
                    orderid = Convert.ToInt32({0}.Database.ExecuteScalar(sql));
                    //删除子栏目
                    sql = ""delete from ["" + TableName + ""] where [id] in ('"" + children.Replace("","",""','"") + ""')"";
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                }}

                //重新更新orderid
                sql = ""update ["" + TableName + ""] set [orderid]=[orderid]-"" + (ug.Child + 1) + "" where [orderid]>"" + orderid;
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                dTran.Commit();
                rt= ReturnType.OK;
            }}
            catch (Exception)
            {{
                rt= ReturnType.Err;
            }}
            finally
            {{
                dConn.Close();
            }}
            return rt;
";
            methodDeleteTree1.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodDeleteTree1);
            #endregion 删除栏目
            #region 删除栏目2
            //            //            //deleteTree2
////            CodeMemberMethod methodDeleteTree2 = new CodeMemberMethod();
////            methodDeleteTree2.Comments.Add(new CodeCommentStatement("<summary>", true));
////            methodDeleteTree2.Comments.Add(new CodeCommentStatement("删除栏目树", true));
////            methodDeleteTree2.Comments.Add(new CodeCommentStatement("</summary>", true));
////            methodDeleteTree2.Comments.Add(new CodeCommentStatement("<param name=\"className\">要删除栏目的名称</param>", true));
////            methodDeleteTree2.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:栏目不存在 </returns>", true));
            ////            methodDeleteTree2.Name = "Delete" + dbsAnalysisClass.Name + "AndChildren";
////            methodDeleteTree2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
////            methodDeleteTree2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
////            methodDeleteTree2.ReturnType = new CodeTypeReference(typeof(Int32));
////            strTemp = @"
////            string sql;
////            string parentpath = """";
////            int id, orderid = 0, rootid = 0, previd = 0, nextid = 0, depth = 0, parentid = 0, Child = 0;
////            sql = ""select * from ["" + TableName + ""] where ClassName = '"" + className + ""'"";
            ////            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
////            if (dr.Read())
////            {{
////                id = Convert.ToInt32(dr[""id""]);
////                parentpath = dr[""parentpath""].ToString();
////                orderid = Convert.ToInt32(dr[""orderid""]);
////                rootid = Convert.ToInt32(dr[""rootid""]);
////                previd = Convert.ToInt32(dr[""previd""]);
////                nextid = Convert.ToInt32(dr[""nextid""]);
////                depth = Convert.ToInt32(dr[""depth""]);
////                parentid = Convert.ToInt32(dr[""parentid""]);
////                Child = Convert.ToInt32(dr[""Child""]);
////            }}
////            else
////            {{
////                dr.Close();
////                dr.Dispose();
////                return 1;//栏目不存在
////            }}
////            dr.Close();
////            dr.Dispose();
////
////            if (depth > 0)
////                //更新父系栏目的子栏目数目
////                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set Child=Child-1 where id="" + parentid);
////
////            //修改上一类别的NextID和下一类别的PrevID
////            if (previd > 0)
////                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set NextID="" + nextid + "" where id="" + previd);
////            if (nextid > 0)
////                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set PrevID="" + previd + "" where id="" + nextid);
////            //删除这个栏目
////            sql = ""delete from ["" + TableName + ""] where id="" + id;
////            {0}.Database.ExecuteNonQuery(sql);
////            if (Child > 0)
////            {{
////                string children = GetChildren(id);
////                //得到最大的orderid,以便后面更新orderid
////                sql = ""select max(orderid) from ["" + TableName + ""] where id in ("" + children + "")"";
////                orderid = Convert.ToInt32({0}.Database.ExecuteScalar(sql));
////                //删除子栏目
////                sql = ""delete from ["" + TableName + ""] where id in ("" + children + "")"";
////                {0}.Database.ExecuteNonQuery(sql);
////            }}
////
////            //重新更新orderid
////            sql = ""update ["" + TableName + ""] set orderid=orderid-"" + (Child + 1) + "" where orderid>"" + orderid;
////            {0}.Database.ExecuteNonQuery(sql);
////            return 0;";
////            methodDeleteTree2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            //            ctd1.Members.Add(methodDeleteTree2);
            #endregion 删除栏目2
            #region 删除全部栏目
            //deleteAllCatalog
            CodeMemberMethod methodDeleteAllCatalog = new CodeMemberMethod();
            methodDeleteAllCatalog.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodDeleteAllCatalog.Comments.Add(new CodeCommentStatement("删除全部栏目", true));
            methodDeleteAllCatalog.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodDeleteAllCatalog.Name = "deleteAll" + dbsAnalysisClass.Name;
            methodDeleteAllCatalog.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            strTemp = @"
            string sql = ""delete from ["" + TableName + ""]"";
            {0}.Database.ExecuteNonQuery(sql);";
            methodDeleteAllCatalog.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodDeleteAllCatalog);
            #endregion 删除全部栏目
            #region 删除栏目
            //deleteClass1
            CodeMemberMethod methodDeleteClass1 = new CodeMemberMethod();
            methodDeleteClass1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodDeleteClass1.Comments.Add(new CodeCommentStatement("删除栏目", true));
            methodDeleteClass1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodDeleteClass1.Comments.Add(new CodeCommentStatement("<param name=\"id\">要删除栏目的id</param>", true));
            methodDeleteClass1.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:栏目不存在 2:该类别含有子类别</returns>", true));
            methodDeleteClass1.Name = "Delete" + dbsAnalysisClass.Name;
            methodDeleteClass1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodDeleteClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodDeleteClass1.ReturnType = new CodeTypeReference("ReturnType");
            strTemp = @"
            ReturnType rt=ReturnType.Err;
            {0} ug = {0}.Get{0}(id);
            if (ug == null)
            {{
                return ReturnType.NoItem;//该栏目不存在
            }}

            if (ug.Child > 0)
                return ReturnType.HaveChild;//该类别含有子类别              
                
            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                if (ug.depth > 0)
                    //更新父系栏目的子栏目数目
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [Child]=[Child]-1 where [id]='"" + ug.ParentID+""'"");
                //修改上一类别的NextID和下一类别的PrevID
                if (!string.IsNullOrEmpty(ug.prevID))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [NextID]='"" + ug.nextID + ""' where [id]='"" + ug.prevID+""'"");
                if (!string.IsNullOrEmpty(ug.nextID))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [PrevID]='"" + ug.prevID + ""' where [id]='"" + ug.nextID+""'"");

                //删除栏目
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""delete from ["" + TableName + ""] where [id]='"" + id+""'"");
                //这个栏目后面的排序orderid全部减1
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set [orderid]=[orderid]-1 where [orderid]>'"" + ug.orderID+""'"");

                dTran.Commit();
                rt= ReturnType.OK;
            }}
            catch (Exception)
            {{
                rt= ReturnType.Err;
            }}
            finally
            {{
                dConn.Close();
            }}
            return rt;";
            methodDeleteClass1.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodDeleteClass1);
            #endregion 删除栏目
            #region 删除栏目2
            //            //deleteClass2
//            CodeMemberMethod methodDeleteClass2 = new CodeMemberMethod();
//            methodDeleteClass2.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodDeleteClass2.Comments.Add(new CodeCommentStatement("删除栏目", true));
//            methodDeleteClass2.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodDeleteClass2.Comments.Add(new CodeCommentStatement("<param name=\"className\">要删除栏目的名称</param>", true));
//            methodDeleteClass2.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:栏目不存在 2:该类别含有子类别</returns>", true));
//            methodDeleteClass2.Name = "deleteClass";
//            methodDeleteClass2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodDeleteClass2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
//            methodDeleteClass2.ReturnType = new CodeTypeReference(typeof(Int32));
//            strTemp = @"
//            string sql;
//            int id, Child, PrevID, NextID, Depth, ParentID, orderid;
//            sql = ""select id,rootID,Depth,ParentID,Child,PrevID,NextID,orderid From ["" + TableName + ""] where className='"" + className + ""'"";
            //            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
//            if (dr.Read())
//            {{
//                id = Convert.ToInt32(dr[""id""]);
//                Child = Convert.ToInt32(dr[""Child""]);
//                PrevID = Convert.ToInt32(dr[""previd""]);
//                NextID = Convert.ToInt32(dr[""nextid""]);
//                Depth = Convert.ToInt32(dr[""depth""]);
//                ParentID = Convert.ToInt32(dr[""parentid""]);
//                orderid = Convert.ToInt32(dr[""orderid""]);
//            }}
//            else
//            {{
//                dr.Close();
//                dr.Dispose();
//                return 1;//该栏目不存在
//            }}
//            dr.Close();
//            dr.Dispose();
//
//            if (Child > 0)
//                return 2;//该类别含有子类别
//
//            if (Depth > 0)
//                //更新父系栏目的子栏目数目
//                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set Child=Child-1 where id="" + ParentID);
//
//            //修改上一类别的NextID和下一类别的PrevID
//            if (PrevID > 0)
//                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set NextID="" + NextID + "" where id="" + PrevID);
//            if (NextID > 0)
//                {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set PrevID="" + PrevID + "" where id="" + NextID);
//
//            //删除栏目
//            {0}.Database.ExecuteNonQuery(""delete from ["" + TableName + ""] where id="" + id);
//            //这个栏目后面的排序orderid全部减1
//            {0}.Database.ExecuteNonQuery(""update ["" + TableName + ""] set orderid=orderid-1 where orderid>"" + orderid);
//
//            return 0;//执行成功
//";
//            methodDeleteClass2.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            ctd1.Members.Add(methodDeleteClass2);
            #endregion 删除栏目2
            #region 向上移动栏目
            //upClass1
            CodeMemberMethod methodUpClass1 = new CodeMemberMethod();
            methodUpClass1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodUpClass1.Comments.Add(new CodeCommentStatement("向上移动栏目", true));
            methodUpClass1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodUpClass1.Comments.Add(new CodeCommentStatement("<param name=\"id\">要向上移动的栏目的id</param>", true));
            methodUpClass1.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:要提升排序的栏目不存在 2:要提升排序的栏目上面没有栏目,无法被提升 3:要提升排序的栏目的这一级别只有它一个，没办法被提升 4:要提升排序的栏目的上面的栏目不存在,被非法删除 5:其它错误</returns>", true));
            methodUpClass1.Name = "Up" + dbsAnalysisClass.Name;
            methodUpClass1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodUpClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodUpClass1.ReturnType = new CodeTypeReference(typeof(Int32));
            strTemp = @"
            string sql;
            //先得到要提升的id的栏目信息
            sql = ""select * from ["" + TableName + ""] where id='"" + id + ""'"";
            int orderid = 0,depth = 0,Child = 0;
            string rootid =string.Empty, previd = string.Empty, nextid = string.Empty,  parentid = string.Empty;
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            if (dr.Read())
            {{
                orderid = Convert.ToInt32(dr[""orderid""]);
                rootid = Convert.ToString(dr[""rootid""]);
                previd = Convert.ToString(dr[""previd""]);
                nextid = Convert.ToString(dr[""nextid""]);
                depth = Convert.ToInt32(dr[""depth""]);
                parentid = Convert.ToString(dr[""parentid""]);
                Child = Convert.ToInt32(dr[""Child""]);
            }}
            else
            {{
                dr.Close();
                dr.Dispose();
                return 1;//要提升排序的栏目不存在
            }}
            dr.Close();
            dr.Dispose();

            if (string.IsNullOrEmpty(previd))
                return 2;//要提升排序的栏目上面没有栏目,无法被提升
            if (string.IsNullOrEmpty(nextid) && string.IsNullOrEmpty(previd))
                return 3;//要提升排序的栏目的这一级别只有它一个，没办法被提升

            //得到上面一个栏目的信息
            sql = ""select * from ["" + TableName + ""] where id='"" + previd + ""'"";
            int orderid_ = 0, depth_ = 0, child_ = 0;
            string rootid_ = string.Empty, previd_ = string.Empty, nextid_ = string.Empty, parentid_ = string.Empty;
            dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            if (dr.Read())
            {{
                orderid_ = Convert.ToInt32(dr[""orderid""]);
                rootid_ = Convert.ToString(dr[""rootid""]);
                previd_ = Convert.ToString(dr[""previd""]);
                nextid_ = Convert.ToString(dr[""nextid""]);
                depth_ = Convert.ToInt32(dr[""depth""]);
                parentid_ = Convert.ToString(dr[""parentid""]);
                child_ = Convert.ToInt32(dr[""Child""]);
            }}
            else
            {{
                dr.Close();
                dr.Dispose();
                return 4;//要提升排序的栏目的上面的栏目不存在,被非法删除
            }}
            dr.Close();
            dr.Dispose();

            int rt=0;
            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                //把原来previd=id的换为previd=previd
                sql = ""update ["" + TableName + ""] set previd='"" + previd + ""' where previd='"" + id + ""'"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                //把原来nextid=previd换为id
                sql = ""update ["" + TableName + ""] set nextid='"" + id + ""' where nextid='"" + previd + ""'"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);

                //处理提升的栏目nextid->previd,previd->previd_,orderid->orderid_
                sql = ""update ["" + TableName + ""] set nextid='"" + previd + ""',previd='"" + previd_ + ""' where id='"" + id + ""'"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);

                int child_num = 0, child_num_ = 0;//两个栏目的子栏目数目
                string[] temp;
                string children, children_;
                children = ""0"";
                children_ = ""0"";

                if (Child > 0)
                {{
                    children = GetChildren(id);
                    temp = children.Split(',');
                    child_num = temp.Length;
                }}
                if (child_ > 0)
                {{
                    children_ = GetChildren(previd);
                    temp = children_.Split(',');
                    child_num_ = temp.Length;
                }}

                //处理上一个栏目nextid->nextid,previd->id
                sql = ""update ["" + TableName + ""] set nextid='"" + nextid + ""',previd='"" + id + ""' where id='"" + previd + ""'"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);

                sql = ""update ["" + TableName + ""] set orderid=orderid - "" + (child_num_ + 1) + "" where id in ('"" + (id + "","" + children).Replace("","",""','"") + ""')"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                sql = ""update ["" + TableName + ""] set orderid=orderid + "" + (child_num + 1) + "" where id in ('"" + (previd + "","" + children_).Replace("","",""','"") + ""')"";
                {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                dTran.Commit();
            }}
            catch (Exception)
            {{
                rt= 5;
            }}
            finally
            {{
                dConn.Close();
            }}

            return rt;
";
            methodUpClass1.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodUpClass1);
            #endregion 向上移动栏目
            #region 向上移动栏目
            //            //upClass2
//            CodeMemberMethod methodUpClass2 = new CodeMemberMethod();
//            methodUpClass2.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodUpClass2.Comments.Add(new CodeCommentStatement("向上移动栏目", true));
//            methodUpClass2.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodUpClass2.Comments.Add(new CodeCommentStatement("<param name=\"className\">要向上移动的栏目的名称</param>", true));
//            methodUpClass2.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:要提升排序的栏目不存在 2:要提升排序的栏目上面没有栏目,无法被提升 3:要提升排序的栏目的这一级别只有它一个，没办法被提升 4:要提升排序的栏目的上面的栏目不存在,被非法删除 </returns>", true));
//            methodUpClass2.Name = "upClass";
//            methodUpClass2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodUpClass2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
//            methodUpClass2.ReturnType = new CodeTypeReference(typeof(Int32));
//            strTemp = @"
//            string sql;
//            //先得到要提升的id的栏目信息
//            sql = ""select * from ["" + TableName + ""] ClassName = '"" + className + ""'"";
//            int id, orderid = 0, rootid = 0, previd = 0, nextid = 0, depth = 0, parentid = 0, Child = 0;
            //            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
//            if (dr.Read())
//            {{
//                id = Convert.ToInt32(dr[""id""]);
//                orderid = Convert.ToInt32(dr[""orderid""]);
//                rootid = Convert.ToInt32(dr[""rootid""]);
//                previd = Convert.ToInt32(dr[""previd""]);
//                nextid = Convert.ToInt32(dr[""nextid""]);
//                depth = Convert.ToInt32(dr[""depth""]);
//                parentid = Convert.ToInt32(dr[""parentid""]);
//                Child = Convert.ToInt32(dr[""Child""]);
//            }}
//            else
//            {{
//                dr.Close();
//                dr.Dispose();
//                return 1;//要提升排序的栏目不存在
//            }}
//            dr.Close();
//            dr.Dispose();
//
//            if (previd == 0)
//                return 2;//要提升排序的栏目上面没有栏目,无法被提升
//            if (nextid == 0 && previd == 0)
//                return 3;//要提升排序的栏目的这一级别只有它一个，没办法被提升
//
//            //得到上面一个栏目的信息
//            sql = ""select * from ["" + TableName + ""] where id="" + previd;
//            int orderid_ = 0, rootid_ = 0, previd_ = 0, nextid_ = 0, depth_ = 0, parentid_ = 0, child_ = 0;
            //            dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
//            if (dr.Read())
//            {{
//                orderid_ = Convert.ToInt32(dr[""orderid""]);
//                rootid_ = Convert.ToInt32(dr[""rootid""]);
//                previd_ = Convert.ToInt32(dr[""previd""]);
//                nextid_ = Convert.ToInt32(dr[""nextid""]);
//                depth_ = Convert.ToInt32(dr[""depth""]);
//                parentid_ = Convert.ToInt32(dr[""parentid""]);
//                child_ = Convert.ToInt32(dr[""Child""]);
//            }}
//            else
//            {{
//                dr.Close();
//                dr.Dispose();
//                return 4;//要提升排序的栏目的上面的栏目不存在,被非法删除
//            }}
//            dr.Close();
//            dr.Dispose();
//
//            //把原来previd=id的换为previd=previd
//            sql = ""update ["" + TableName + ""] set previd="" + previd + "" where previd="" + id;
//            {0}.Database.ExecuteNonQuery(sql);
//            //把原来nextid=previd换为id
//            sql = ""update ["" + TableName + ""] set nextid="" + id + "" where nextid="" + previd;
//            {0}.Database.ExecuteNonQuery(sql);
//
//            //处理提升的栏目nextid->previd,previd->previd_,orderid->orderid_
//            sql = ""update ["" + TableName + ""] set nextid="" + previd + "",previd="" + previd_ + "" where id="" + id;
//            {0}.Database.ExecuteNonQuery(sql);
//
//            int child_num = 0, child_num_ = 0;//两个栏目的子栏目数目
//            string[] temp;
//            string children, children_;
//            children = ""0"";
//            children_ = ""0"";
//
//            if (Child > 0)
//            {{
//                children = GetChildren(id);
//                temp = children.Split(',');
//                child_num = temp.Length;
//            }}
//            if (child_ > 0)
//            {{
//                children_ = GetChildren(previd);
//                temp = children_.Split(',');
//                child_num_ = temp.Length;
//            }}
//
//            //处理上一个栏目nextid->nextid,previd->id
//            sql = ""update ["" + TableName + ""] set nextid="" + nextid + "",previd="" + id + "" where id="" + previd;
//            {0}.Database.ExecuteNonQuery(sql);
//
//            sql = ""update ["" + TableName + ""] set orderid=orderid - "" + (child_num_ + 1) + "" where id in ("" + (id + "","" + children) + "")"";
//            {0}.Database.ExecuteNonQuery(sql);
//            sql = ""update ["" + TableName + ""] set orderid=orderid + "" + (child_num + 1) + "" where id in ("" + (previd + "","" + children_) + "")"";
//            {0}.Database.ExecuteNonQuery(sql);
//
//            return 0;
//";
//            methodUpClass2.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
//            ctd1.Members.Add(methodUpClass2);
#endregion 
            #region 向下移动栏目
            //downClass1
            CodeMemberMethod methodDownClass1 = new CodeMemberMethod();
            methodDownClass1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodDownClass1.Comments.Add(new CodeCommentStatement("向下移动栏目", true));
            methodDownClass1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodDownClass1.Comments.Add(new CodeCommentStatement("<param name=\"id\">要向下移动的栏目的id</param>", true));
            methodDownClass1.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:要下降排序的栏目不存在 2:要下降排序的栏目下面没有栏目,无法被下降 3:要下降排序的栏目的这一级别只有它一个，没办法被提升</returns>", true));
            methodDownClass1.Name = "Down" + dbsAnalysisClass.Name;
            methodDownClass1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodDownClass1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodDownClass1.ReturnType = new CodeTypeReference(typeof(Int32));
            strTemp = @"
            string sql;
            sql = ""select * from ["" + TableName + ""] where id='"" + id + ""'"";
            int orderid = 0,depth = 0, Child = 0;
            string rootid = string.Empty, previd = string.Empty, nextid = string.Empty,  parentid = string.Empty;
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            if (dr.Read())
            {{
                orderid = Convert.ToInt32(dr[""orderid""]);
                rootid = Convert.ToString(dr[""rootid""]);
                previd = Convert.ToString(dr[""previd""]);
                nextid = Convert.ToString(dr[""nextid""]);
                depth = Convert.ToInt32(dr[""depth""]);
                parentid = Convert.ToString(dr[""parentid""]);
                Child = Convert.ToInt32(dr[""Child""]);
            }}
            else
            {{
                dr.Close();
                dr.Dispose();
                return 1;//要下降排序的栏目不存在
            }}
            dr.Close();
            dr.Dispose();

            if (string.IsNullOrEmpty(nextid))
                return 2;//要下降排序的栏目下面没有栏目,无法被下降
            if (string.IsNullOrEmpty(nextid) && string.IsNullOrEmpty(previd))
                return 3;//要下降排序的栏目的这一级别只有它一个，没办法被提升

            return Up{0}(nextid);
";
            methodDownClass1.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodDownClass1);
            #endregion 向下移动栏目
            #region 向下移动栏目
            //            //downClass2
            //            CodeMemberMethod methodDownClass2 = new CodeMemberMethod();
//            methodDownClass2.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodDownClass2.Comments.Add(new CodeCommentStatement("向下移动栏目", true));
//            methodDownClass2.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodDownClass2.Comments.Add(new CodeCommentStatement("<param name=\"className\">要向下移动的栏目的名称</param>", true));
//            methodDownClass2.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:要下降排序的栏目不存在 2:要下降排序的栏目下面没有栏目,无法被下降 3:要下降排序的栏目的这一级别只有它一个，没办法被提升 </returns>", true));
//            methodDownClass2.Name = "downClass";
//            methodDownClass2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodDownClass2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
//            methodDownClass2.ReturnType = new CodeTypeReference(typeof(Int32));
//            strTemp = @"
//            string sql;
//            sql = ""select * from ["" + TableName + ""] where  ClassName = '"" + className + ""'"";
//            int id, orderid = 0, rootid = 0, previd = 0, nextid = 0, depth = 0, parentid = 0, Child = 0;
            //            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
//            if (dr.Read())
//            {{
//                id = Convert.ToInt32(dr[""id""]);
//                orderid = Convert.ToInt32(dr[""orderid""]);
//                rootid = Convert.ToInt32(dr[""rootid""]);
//                previd = Convert.ToInt32(dr[""previd""]);
//                nextid = Convert.ToInt32(dr[""nextid""]);
//                depth = Convert.ToInt32(dr[""depth""]);
//                parentid = Convert.ToInt32(dr[""parentid""]);
//                Child = Convert.ToInt32(dr[""Child""]);
//            }}
//            else
//            {{
//                dr.Close();
//                dr.Dispose();
//                return 1;//要下降排序的栏目不存在
//            }}
//            dr.Close();
//            dr.Dispose();
//
//            if (nextid == 0)
//                return 2;//要下降排序的栏目下面没有栏目,无法被下降
//            if (nextid == 0 && previd == 0)
//                return 3;//要下降排序的栏目的这一级别只有它一个，没办法被提升
//
//            return upClass(nextid);
//";
//            methodDownClass2.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            ctd1.Members.Add(methodDownClass2);
            #endregion 向下移动栏目
            #region 显示栏目列表的
            //List1
            CodeMemberMethod methodList1 = new CodeMemberMethod();
            methodList1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodList1.Comments.Add(new CodeCommentStatement("显示全部栏目列表的dataTableName", true));
            methodList1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodList1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodList1.Name = "List" + dbsAnalysisClass.Name;
            methodList1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodList1.ReturnType = new CodeTypeReference("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">");
            methodList1.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodList1.Statements.Add(new CodeSnippetExpression("return List" + dbsAnalysisClass.Name + "(\"\")"));
            ctd1.Members.Add(methodList1);
            #endregion 显示栏目列表的
            #region 显示栏目列表的
            //List2
            CodeMemberMethod methodList2 = new CodeMemberMethod();
            methodList2.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodList2.Comments.Add(new CodeCommentStatement("显示栏目列表的dataTableName", true));
            methodList2.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodList2.Comments.Add(new CodeCommentStatement("<param name=\"catalogId\">要获得子栏目的 Id</param>", true));
            methodList2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodList2.Name = "List" + dbsAnalysisClass.Name;
            methodList2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodList2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "catalogId"));
            methodList2.ReturnType = new CodeTypeReference("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">");
            methodList2.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            strTemp = @"
            System.Collections.Generic.List<" + dbsAnalysisClass.Name + @"> temp1 =null;
            System.Collections.Generic.List<" + dbsAnalysisClass.Name + @"> temp2 = new System.Collections.Generic.List<" + dbsAnalysisClass.Name + @">();
            if (string.IsNullOrEmpty(catalogId))
            {{
                temp1 = Select{0}(0, 1, """", ""OrderID"");
            }}
            else
            {{
                temp1 = Select{0}(0, 1, ""ParentPath || ',' like '%,"" + catalogId + "",%'"", ""OrderID"");
            }}
            orderByCatalog(catalogId,temp1,temp2);
            return temp2;";
            methodList2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodList2);
            #endregion 显示栏目列表的
            #region 显示栏目列表的
            //            //List3
//            CodeMemberMethod methodList3 = new CodeMemberMethod();
//            methodList3.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodList3.Comments.Add(new CodeCommentStatement("显示栏目列表的dataTableName", true));
//            methodList3.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodList3.Comments.Add(new CodeCommentStatement("<param name=\"ClassName\">要获得子栏目的名称</param>", true));
//            methodList3.Comments.Add(new CodeCommentStatement("<param name=\"IsLike\">是否模糊查找</param>", true));
//            methodList3.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
//            methodList3.Name = "list";
//            methodList3.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodList3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ClassName"));
//            methodList3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Boolean), "IsLike"));
//            methodList3.ReturnType = new CodeTypeReference("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">");
//            strTemp = @"
//            System.Collections.Generic.List<" + dbsAnalysisClass.Name + @"> temp1 =null;
//            System.Collections.Generic.List<" + dbsAnalysisClass.Name + @"> temp2 = new System.Collections.Generic.List<" + dbsAnalysisClass.Name + @">();
//            if (ClassName == """")
//            {{
//                temp1= Select{0}(0, 1, """", ""OrderID"");
//            }}
//            else if (IsLike)
//            {{
//                temp1= Select{0}(0, 1, ""ClassName + ',' like '%"" + ClassName + ""%'"", ""OrderID"");
//            }}
//            else
//            {{
//                temp1= Select{0}(0, 1, ""ClassName = '"" + ClassName + ""'"", ""OrderID"");
//            }}
//            orderByCatalog(-1,temp1,temp2);
//            return temp2;
//    ";
//            methodList3.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            ctd1.Members.Add(methodList3);
            #endregion 显示栏目列表的
            #region orderByCatalog
            //orderByCatalog
            CodeMemberMethod orderByCatalog = new CodeMemberMethod();
            orderByCatalog.Comments.Add(new CodeCommentStatement("<summary>", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("排序Catalog", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("</summary>", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("<param name=\"catalogId\">catalogId</param>", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("<param name=\"lstCatalog1\">原始lstCatalog</param>", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("<param name=\"lstCatalog2\">处理后lstCatalog</param>", true));
            orderByCatalog.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            orderByCatalog.Name = "orderByCatalog";
            orderByCatalog.Attributes = MemberAttributes.Private | MemberAttributes.Static;
            orderByCatalog.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "catalogId"));
            orderByCatalog.Parameters.Add(new CodeParameterDeclarationExpression("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">", "lstCatalog1"));
            orderByCatalog.Parameters.Add(new CodeParameterDeclarationExpression("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">", "lstCatalog2"));
            orderByCatalog.ReturnType = new CodeTypeReference(typeof(void));
            strTemp = @"
            if (catalogId == null) {{ catalogId = """"; }}
            //if (string.IsNullOrEmpty( catalogId))
            //{{
            //    if (lstCatalog1.Count > 0)
            //    {{
            //        catalogId = lstCatalog1[0].ParentID;
            //    }}
            //    for (int i = 0; i < lstCatalog1.Count; i++)
            //    {{
            //        if (lstCatalog1[i].ParentID < catalogId)
            //        {{
            //            catalogId = lstCatalog1[i].ParentID;
            //        }}
            //    }}
            //}}
            for (int i = 0; i < lstCatalog1.Count; i++)
            {{
                if (catalogId == lstCatalog1[i].ParentID)
                {{
                    lstCatalog2.Add(lstCatalog1[i]);
                    orderByCatalog(lstCatalog1[i].Id, lstCatalog1, lstCatalog2);
                }}
            }}";
            orderByCatalog.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(orderByCatalog);
            #endregion orderByCatalog
            #region TreeList
            //TreeList1
            CodeMemberMethod methodTreeList1 = new CodeMemberMethod();
            methodTreeList1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodTreeList1.Comments.Add(new CodeCommentStatement("显示栏目列表的" + dbsAnalysisClass.Name + "DataSource", true));
            methodTreeList1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodTreeList1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodTreeList1.Name = "TreeList" + dbsAnalysisClass.Name;
            methodTreeList1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodTreeList1.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
            methodTreeList1.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodTreeList1.Statements.Add(new CodeSnippetExpression("return " + dbsAnalysisClass.Name + "DataSource.Select()"));
            ctd1.Members.Add(methodTreeList1);
            #endregion TreeList
            #region TreeList
            //TreeList2
            CodeMemberMethod methodTreeList2 = new CodeMemberMethod();
            methodTreeList2.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodTreeList2.Comments.Add(new CodeCommentStatement("显示栏目列表的" + dbsAnalysisClass.Name + "DataSource", true));
            methodTreeList2.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodTreeList2.Comments.Add(new CodeCommentStatement("<param name=\"id\">要获得子栏目的id</param>", true));
            methodTreeList2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodTreeList2.Name = "TreeList" + dbsAnalysisClass.Name;
            methodTreeList2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodTreeList2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodTreeList2.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
            methodTreeList2.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodTreeList2.Statements.Add(new CodeSnippetExpression("return " + dbsAnalysisClass.Name + "DataSource.Select(id)"));
            ctd1.Members.Add(methodTreeList2);
            #endregion TreeList
            #region TreeList
            //            //TreeList3
//            CodeMemberMethod methodTreeList3 = new CodeMemberMethod();
//            methodTreeList3.Comments.Add(new CodeCommentStatement("<summary>", true));
//            methodTreeList3.Comments.Add(new CodeCommentStatement("显示栏目列表的" + dbsAnalysisClass.Name + "DataSource", true));
//            methodTreeList3.Comments.Add(new CodeCommentStatement("</summary>", true));
//            methodTreeList3.Comments.Add(new CodeCommentStatement("<param name=\"ClassName\">要获得子栏目的名称</param>", true));
//            methodTreeList3.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
//            methodTreeList3.Name = "TreeList";
//            methodTreeList3.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            methodTreeList3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ClassName"));
//            methodTreeList3.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
//            methodTreeList3.Statements.Add(new CodeSnippetExpression("return " + dbsAnalysisClass.Name + "DataSource.Select(ClassName)"));
            //            ctd1.Members.Add(methodTreeList3);
            #endregion TreeList
            #region 检查栏目是否存在
            //checkExist1
            CodeMemberMethod methodCheckExist1 = new CodeMemberMethod();
            methodCheckExist1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodCheckExist1.Comments.Add(new CodeCommentStatement("检查栏目是否存在", true));
            methodCheckExist1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodCheckExist1.Comments.Add(new CodeCommentStatement("<param name=\"id\"></param>", true));
            methodCheckExist1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodCheckExist1.Name = "CheckExist";
            methodCheckExist1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodCheckExist1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodCheckExist1.ReturnType = new CodeTypeReference(typeof(bool));
            strTemp = @"
            string sql;
            sql = ""select rootid From ["" + TableName + ""] where id='"" + id + ""'"";
            if ({0}.Database.ExecuteScalar(sql) == null)
            {{
                return false;
            }}
            else
            {{
                return true;
            }}
";
            methodCheckExist1.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodCheckExist1);
            #endregion 检查栏目是否存在
            #region 检查栏目是否存在
            //            //checkExist2
            //            CodeMemberMethod methodCheckExist2 = new CodeMemberMethod();
            //            methodCheckExist2.Comments.Add(new CodeCommentStatement("<summary>", true));
            //            methodCheckExist2.Comments.Add(new CodeCommentStatement("检查栏目是否存在", true));
            //            methodCheckExist2.Comments.Add(new CodeCommentStatement("</summary>", true));
            //            methodCheckExist2.Comments.Add(new CodeCommentStatement("<param name=\"className\"></param>", true));
            //            methodCheckExist2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            //            methodCheckExist2.Name = "checkExist";
            //            methodCheckExist2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //            methodCheckExist2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "className"));
            //            methodCheckExist2.ReturnType = new CodeTypeReference(typeof(bool));
            //            strTemp = @"
            //            string sql;
            //            sql = ""select rootid From ["" + TableName + ""] where className='"" + className + ""'"";
            //            if ({0}.Database.ExecuteScalar(sql) == null)
            //            {{
            //                return false;
            //            }}
            //            else
            //            {{
            //                return true;
            //            }}
            //";
            //            methodCheckExist2.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            ctd1.Members.Add(methodCheckExist2);
            #endregion 检查栏目是否存在
            #region 复位
            //reset
            CodeMemberMethod methodReset = new CodeMemberMethod();
            methodReset.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodReset.Comments.Add(new CodeCommentStatement("复位", true));
            methodReset.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodReset.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodReset.Name = "Reset";
            methodReset.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //methodReset.ReturnType = new CodeTypeReference(typeof(int));
            strTemp = @"
            string sql;
            System.Collections.ArrayList arr = new System.Collections.ArrayList();
            string PrevID, NextID;

            PrevID = string.Empty;
            sql = ""select id From ["" + TableName + ""] order by [rootID],[OrderID]"";
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);

            while (dr.Read())
            {{
                arr.Add(dr[""id""]);
            }}
            dr.Close();
            dr.Dispose();

            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                for (int j = 0; j < arr.Count; j++)
                {{
                    if (j == arr.Count - 1)
                        NextID = string.Empty;
                    else
                        NextID = Convert.ToString(arr[j + 1]);

                    sql = ""update ["" + TableName + ""] set rootID='"" + arr[j] + ""',OrderID="" + (j + 1) + "",ParentID='',Child=0,ParentPath=',',Depth=0,PrevID='"" + PrevID + ""',NextID='"" + NextID + ""' where id='"" + arr[j]+""'"";
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,sql);
                    PrevID = Convert.ToString(arr[j]);
                }}
                dTran.Commit();
            }}
            finally
            {{
                dConn.Close();
            }}
";
            methodReset.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodReset);
            #endregion 复位
            #region 得到 ListItem 栏目列表
            //GetListItem1
            CodeMemberMethod methodGetListItem1 = new CodeMemberMethod();
            methodGetListItem1.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodGetListItem1.Comments.Add(new CodeCommentStatement("得到 ListItem 栏目列表", true));
            methodGetListItem1.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodGetListItem1.Comments.Add(new CodeCommentStatement("<param name=\"catalogId\"></param>", true));
            methodGetListItem1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodGetListItem1.Name = "GetListItem";
            methodGetListItem1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodGetListItem1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "catalogId"));
            methodGetListItem1.ReturnType = new CodeTypeReference("System.Collections.Generic.List<System.Web.UI.WebControls.ListItem>");
            methodGetListItem1.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodGetListItem1.Statements.Add(new CodeSnippetExpression("return GetListItem(0, catalogId,\"\",\"\")"));
            ctd1.Members.Add(methodGetListItem1);
            #endregion 得到 ListItem 栏目列表
            #region 得到 ListItem 栏目列表
            //GetListItem1
            CodeMemberMethod methodGetListItem3 = new CodeMemberMethod();
            methodGetListItem3.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodGetListItem3.Comments.Add(new CodeCommentStatement("得到 ListItem 栏目列表", true));
            methodGetListItem3.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodGetListItem3.Comments.Add(new CodeCommentStatement("<param name=\"catalogId\"></param>", true));
            methodGetListItem3.Comments.Add(new CodeCommentStatement("<param name=\"propertyInfo\"></param>", true));
            methodGetListItem3.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodGetListItem3.Name = "GetListItem";
            methodGetListItem3.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodGetListItem3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "catalogId"));
            methodGetListItem3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "propertyInfo"));
            methodGetListItem3.ReturnType = new CodeTypeReference("System.Collections.Generic.List<System.Web.UI.WebControls.ListItem>");
            methodGetListItem3.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodGetListItem3.Statements.Add(new CodeSnippetExpression("return GetListItem(0, catalogId,propertyInfo,\"\")"));
            ctd1.Members.Add(methodGetListItem3);
            #endregion 得到 ListItem 栏目列表

            #region 得到 ListItem 栏目列表
            //GetListItem2
            CodeMemberMethod methodGetListItem2 = new CodeMemberMethod();
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("得到 ListItem 栏目列表", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<param name=\"type\">0:显示\"请先添加类别\";1:显示\"无（作为一级类别）\"2:没有子栏目Value设为\"0\"</param>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<param name=\"catalogId\"></param>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<param name=\"propertyInfo\"></param>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<param name=\"selected\"></param>", true));
            methodGetListItem2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            methodGetListItem2.Name = "GetListItem";
            methodGetListItem2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodGetListItem2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "type"));
            methodGetListItem2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "catalogId"));
            methodGetListItem2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "propertyInfo"));
            methodGetListItem2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "selected"));
            methodGetListItem2.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            methodGetListItem2.ReturnType = new CodeTypeReference("System.Collections.Generic.List<System.Web.UI.WebControls.ListItem>");
            strTemp = @"
            System.Collections.Generic.List<System.Web.UI.WebControls.ListItem> lic = new System.Collections.Generic.List<System.Web.UI.WebControls.ListItem>();
            int rootDepth = string.IsNullOrEmpty(catalogId) ? 0 : Get{0}(catalogId).depth + 1;
            System.Collections.Generic.List<{0}> dt = {0}.List{0}(catalogId);//得到列表
            if (dt.Count == 0 && type == 0)//显示""请先添加类别""
            {{
                System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem(""请先添加类别"", catalogId);
                lic.Add(li);
                return lic;
            }}
            if (type == 1)//显示""无（作为一级类别）""
            {{
                System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem(""无（作为一级类别）"", catalogId);
                lic.Add(li);
            }}

            foreach ({0} dr in dt)
            {{
                System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem();

                int tmpDepth = dr.depth - rootDepth;
                string NextID = dr.nextID;
                string id = dr.Id;
                int Child = dr.Child;
                string liText = string.IsNullOrEmpty(propertyInfo) ? dr.ToString() : typeof({0}).GetProperty(propertyInfo, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(dr, null).ToString();

                try
                {{
                    showLine[tmpDepth] = string.IsNullOrEmpty(NextID) ? false : true;//这个值是经常被修改的.
                }}
                catch//(Exception ex)
                {{
                    showLine.Add(false);
                    showLine[tmpDepth] = string.IsNullOrEmpty(NextID) ? false : true;//这个值是经常被修改的.
                }}
                //默认选择的项
                if (id == selected)
                {{
                    li.Selected = true;
                    li.Value = id.ToString();
                }}
                else
                {{
                    if (type == 2 && Child > 0)//添加文章的时候,有子栏目的栏目的value这里也设置为0
                        li.Value = """";
                    else
                        li.Value = id.ToString();
                }}
                li.Text = """";
                if (tmpDepth > 0)
                {{
                    for (int j = 1; j <= tmpDepth; j++)
                    {{
                        li.Text += nbsp + nbsp;// ""&nbsp;&nbsp;"";
                        if (j == tmpDepth)
                        {{
                            if (string.IsNullOrEmpty(NextID))
                                li.Text += ""└"" + nbsp;
                            else
                                li.Text += ""├"" + nbsp;
                        }}
                        else
                        {{
                            if ((bool)showLine[j])
                                li.Text += ""│"";
                            else
                                li.Text += nbsp;
                        }}
                    }}
                }}
                li.Text += liText;
                lic.Add(li);
            }}

            return lic;";
            methodGetListItem2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodGetListItem2);
            #endregion 得到 ListItem 栏目列表
            #region 得到栏目的排的顺序
            //getClassName
            CodeMemberMethod MethodGetClassidOrderNum = new CodeMemberMethod();
            MethodGetClassidOrderNum.Comments.Add(new CodeCommentStatement("<summary>", true));
            MethodGetClassidOrderNum.Comments.Add(new CodeCommentStatement("得到栏目的排的顺序", true));
            MethodGetClassidOrderNum.Comments.Add(new CodeCommentStatement("</summary>", true));
            MethodGetClassidOrderNum.Comments.Add(new CodeCommentStatement("<param name=\"id\"></param>", true));
            MethodGetClassidOrderNum.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            MethodGetClassidOrderNum.Name = "GetClassidOrderNum";
            MethodGetClassidOrderNum.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            MethodGetClassidOrderNum.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            MethodGetClassidOrderNum.ReturnType = new CodeTypeReference(typeof(int));
            strTemp = @"
            string sql;
            int i = 0;
            sql = ""select id From ["" + TableName + ""] order by rootID,OrderID"";
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            while (dr.Read())
            {{
                i = i + 1;
                if (Convert.ToString(dr[""id""]) == id)
                    break;
                else
                {{
                    continue;
                }}
            }}
            dr.Close();
            dr.Dispose();
            return i;
";
            MethodGetClassidOrderNum.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(MethodGetClassidOrderNum);
            #endregion 得到栏目的排的顺序
            #region 罗列一栏目下的所有级别的子栏目
            //GetChildren
            CodeMemberMethod MethodGetChildren = new CodeMemberMethod();
            MethodGetChildren.Comments.Add(new CodeCommentStatement("<summary>", true));
            MethodGetChildren.Comments.Add(new CodeCommentStatement("罗列一栏目下的所有级别的子栏目", true));
            MethodGetChildren.Comments.Add(new CodeCommentStatement("</summary>", true));
            MethodGetChildren.Comments.Add(new CodeCommentStatement("<param name=\"id\"></param>", true));
            MethodGetChildren.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            MethodGetChildren.Name = "GetChildren";
            MethodGetChildren.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            MethodGetChildren.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            MethodGetChildren.ReturnType = new CodeTypeReference(typeof(string));
            MethodGetChildren.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            strTemp = @"
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string sql;
//            if (id <= 0)
//                return """";
            sql = ""select id from ["" + TableName + ""] where  ParentPath || ',' like '%,"" + id + "",%' order by orderid"";
            //_____________________________________________________________________________________按照先后顺序
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            while (dr.Read())
            {{
                sb.Append(dr[0].ToString() + "","");
            }}
            dr.Close();
            dr.Dispose();

            string rtn = sb.ToString();
            if (rtn != """")
                rtn = rtn.Substring(0, rtn.Length - 1);//去掉末尾的"",""
            return rtn;";
            MethodGetChildren.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(MethodGetChildren);
            #endregion 罗列一栏目下的所有级别的子栏目
            #region 罗列一栏目下的子栏目
            //GetChild1
            CodeMemberMethod MethodGetChild1 = new CodeMemberMethod();
            MethodGetChild1.Comments.Add(new CodeCommentStatement("<summary>", true));
            MethodGetChild1.Comments.Add(new CodeCommentStatement("罗列一栏目下的子栏目", true));
            MethodGetChild1.Comments.Add(new CodeCommentStatement("</summary>", true));
            MethodGetChild1.Comments.Add(new CodeCommentStatement("<param name=\"ChildId\"></param>", true));
            MethodGetChild1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            MethodGetChild1.Name = "GetChild";
            MethodGetChild1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            MethodGetChild1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ChildId"));
            MethodGetChild1.ReturnType = new CodeTypeReference("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">");
            MethodGetChild1.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            strTemp = @"
            return Select{0}(0, 1, ""ParentID='"" + ChildId + ""'"", ""orderid"")";
            MethodGetChild1.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(MethodGetChild1);
            #endregion 罗列一栏目下的子栏目
            #region 罗列一栏目下的子栏目
            //            //GetChild2
            //            CodeMemberMethod MethodGetChild2 = new CodeMemberMethod();
            //            MethodGetChild2.Comments.Add(new CodeCommentStatement("<summary>", true));
            //            MethodGetChild2.Comments.Add(new CodeCommentStatement("罗列一栏目下的子栏目", true));
            //            MethodGetChild2.Comments.Add(new CodeCommentStatement("</summary>", true));
            //            MethodGetChild2.Comments.Add(new CodeCommentStatement("<param name=\"ClassName\"></param>", true));
            //            MethodGetChild2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            //            MethodGetChild2.Name = "GetChild";
            //            MethodGetChild2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //            MethodGetChild2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ClassName"));
            //            MethodGetChild2.ReturnType = new CodeTypeReference("System.Collections.Generic.List<" + dbsAnalysisClass.Name + ">");
            //            strTemp = @"
            //            return GetChild({0}.Search{0}(ClassName).Id)";
            //            MethodGetChild2.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
            //            ctd1.Members.Add(MethodGetChild2);
            #endregion 罗列一栏目下的子栏目
            #region 栏目map
                        //classMap
            CodeMemberMethod MethodClassMap = new CodeMemberMethod();
            MethodClassMap.Comments.Add(new CodeCommentStatement("<summary>", true));
            MethodClassMap.Comments.Add(new CodeCommentStatement("栏目map", true));
            MethodClassMap.Comments.Add(new CodeCommentStatement("</summary>", true));
            MethodClassMap.Comments.Add(new CodeCommentStatement("<param name=\"id\"></param>", true));
            MethodClassMap.Comments.Add(new CodeCommentStatement("<param name=\"Title\"></param>", true));
            MethodClassMap.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            MethodClassMap.Name = "ClassMap";
            MethodClassMap.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            MethodClassMap.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.ID.Type, "id"));
            MethodClassMap.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "Title"));
            MethodClassMap.ReturnType = new CodeTypeReference(typeof(string));
            MethodClassMap.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            strTemp = @"
            string sql;
            object temp;
            sql = ""select parentid from ["" + TableName + ""] where id='"" + id + ""'"";
            temp = {0}.Database.ExecuteScalar(sql);
            if (temp == null)
                return """";
            else
            {{
                if (string.IsNullOrEmpty(Convert.ToString(temp)))
                    return ""一级栏目"";
            }}

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //栏目路径
            string parentpath;
            parentpath = (string){0}.Database.ExecuteScalar(""select parentpath from ["" + TableName + ""] where id='"" + id + ""'"");
            sql = ""Select * From ["" + TableName + ""] where id in ('"" + parentpath.Replace("","",""','"") + ""') order by Depth"";
            System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
            while (dr.Read())
            {{
                int Depth = Convert.ToInt32(dr[""Depth""]);
                string classname = (string)dr[Title];
                for (int i = 1; i <= Depth; i++) {{ sb.Append(""&nbsp;&nbsp;&nbsp;""); }}
                if (Depth > 0)
                    sb.Append(""└"");
                sb.AppendFormat(""&nbsp;{{0}}<br />"", classname);
            }}
            dr.Close();
            dr.Dispose();

            return sb.ToString();
";
            MethodClassMap.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(MethodClassMap);
            #endregion 栏目map
            #region 栏目Map名称
            ////GetMapText
            //CodeMemberMethod MethodGetMapText1 = new CodeMemberMethod();
            //MethodGetMapText1.Comments.Add(new CodeCommentStatement("<summary>", true));
            //MethodGetMapText1.Comments.Add(new CodeCommentStatement("根据id得到栏目名称", true));
            //MethodGetMapText1.Comments.Add(new CodeCommentStatement("</summary>", true));
            //MethodGetMapText1.Comments.Add(new CodeCommentStatement("<param name=\"dr\"></param>", true));
            //MethodGetMapText1.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            //MethodGetMapText1.Name = "GetMapText";
            //MethodGetMapText1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //MethodGetMapText1.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "dr"));
            //MethodGetMapText1.ReturnType = new CodeTypeReference(typeof(string));
            //MethodGetMapText1.Statements.Add(new CodeSnippetExpression("return GetMapText(dr.,dr)"));
            //ctd1.Members.Add(MethodGetMapText1);
            #endregion 栏目Map名称
            #region 栏目Map名称
            //GetMapText
            CodeMemberMethod MethodGetMapText2 = new CodeMemberMethod();
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("<summary>", true));
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("根据id得到栏目名称", true));
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("</summary>", true));
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("<param name=\"rootDepth\"></param>", true));
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("<param name=\"dr\"></param>", true));
            MethodGetMapText2.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            MethodGetMapText2.Name = "GetMapText";
            MethodGetMapText2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            MethodGetMapText2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Int32), "rootDepth"));
            MethodGetMapText2.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "dr"));
            MethodGetMapText2.ReturnType = new CodeTypeReference(typeof(string));
            MethodGetMapText2.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ComponentModel.DataObjectMethodAttribute)), new System.CodeDom.CodeAttributeArgument(new System.CodeDom.CodeArgumentReferenceExpression("System.ComponentModel.DataObjectMethodType.Select , false"))));
            strTemp = @"
            int tmpDepth = dr.depth - rootDepth;
            string NextID = dr.nextID;
            string id = dr.Id;
            int child = dr.Child;
            string liText = dr.ToString();

            try
            {{
                showLine[tmpDepth] = string.IsNullOrEmpty(NextID) ? false : true;//这个值是经常被修改的.
            }}
            catch//(Exception ex)
            {{
                showLine.Add(false);
                showLine[tmpDepth] = string.IsNullOrEmpty(NextID) ? false : true;//这个值是经常被修改的.
            }}

            string r = string.Empty;
            if (tmpDepth > 0)
            {{
                for (int j = 1; j <= tmpDepth; j++)
                {{
                    r += nbsp + nbsp;// ""&nbsp;&nbsp;"";
                    if (j == tmpDepth)
                    {{
                        if (string.IsNullOrEmpty(NextID))
                            r += ""└"" + nbsp;
                        else
                            r += ""├"" + nbsp;
                    }}
                    else
                    {{
                        if ((bool)showLine[j])
                            r += ""│"";
                        else
                            r += nbsp;
                    }}
                }}
            }}
            return r;";
            MethodGetMapText2.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(MethodGetMapText2);
            #endregion 栏目Map名称

            #endregion 方法
            #region 更改栏目路径
            //MoveClass
            CodeMemberMethod methodMoveClass = new CodeMemberMethod();
            methodMoveClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            methodMoveClass.Comments.Add(new CodeCommentStatement("移动栏目", true));
            methodMoveClass.Comments.Add(new CodeCommentStatement("</summary>", true));
            methodMoveClass.Comments.Add(new CodeCommentStatement("<param name=\"id\">要向下移动的栏目的id</param>", true));
            methodMoveClass.Comments.Add(new CodeCommentStatement("<param name=\"target\"></param>", true));
            methodMoveClass.Comments.Add(new CodeCommentStatement("<returns>0:成功 1:要移动的栏目不存在 2:目标栏目不存在 3:不能指定该类别的下属类别作为所属类别 4:其他错误 </returns>", true));
            methodMoveClass.Name = "Move" + dbsAnalysisClass.Name;
            methodMoveClass.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodMoveClass.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodMoveClass.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "target"));
            methodMoveClass.ReturnType = new CodeTypeReference(typeof(Int32));
            strTemp = @"
            if (id == target) {{ return 3; }}
            if (!CheckExist(id))
                return 1;//要移动的栏目不存在
            if (!string.IsNullOrEmpty(target))
            {{
                if (!CheckExist(target))
                    return 2;//目标栏目不存在
            }}

            //要移动的类别的所有的子栏目
            string moveclassids;
            moveclassids = GetChildren(id);
            string[] arr = moveclassids.Split(',');
            string temp = "","" + moveclassids;
            if (!string.IsNullOrEmpty(target) && temp.IndexOf("","" + target.ToString()) != -1)
                return 3;//不能指定该类别的下属类别作为所属类别

            string sql;


            int rt=0;
            System.Data.Common.DbConnection dConn = {0}.Database.CreateConnection();
            dConn.Open();
            System.Data.Common.DbTransaction dTran = dConn.BeginTransaction();
            try
            {{
                #region 先处理要移动的栏目的信息
                string parentpath = """";
                int orderid = 0, depth = 0, Child = 0;
                string  rootid = string.Empty, previd = string.Empty, nextid = string.Empty,parentid = string.Empty;
                int last_orderid = 0;
                sql = ""select * from ["" + TableName + ""] where id='"" + id + ""'"";
                System.Data.IDataReader dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
                if (dr.Read())
                {{
                    parentpath = Convert.ToString(dr[""parentpath""]);
                    orderid = Convert.ToInt32(dr[""orderid""]);
                    rootid = Convert.ToString(dr[""rootid""]);
                    previd = Convert.ToString(dr[""previd""]);
                    nextid = Convert.ToString(dr[""nextid""]);
                    depth = Convert.ToInt32(dr[""depth""]);
                    parentid = Convert.ToString(dr[""parentid""]);
                    Child = Convert.ToInt32(dr[""Child""]);
                }}
                dr.Close();
                dr.Dispose();

                if (depth > 0)
                    //更新父系栏目的子栏目数目
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set Child=Child-1 where id='"" + parentid + ""'"");

                //修改上一类别的NextID和下一类别的PrevID
                if (!string.IsNullOrEmpty(previd))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set NextID='"" + nextid + ""' where id='"" + previd + ""'"");
                if (!string.IsNullOrEmpty(nextid))
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set PrevID='"" + previd + ""' where id='"" + nextid + ""'"");

                //得到要移动的栏目的子栏目里最大的orderid
                if (Child > 0)
                {{
                    sql = ""select max(orderid) from ["" + TableName + ""] where id in ('"" + moveclassids.Replace("","",""','"") + ""')"";
                    last_orderid = Convert.ToInt32({0}.Database.ExecuteScalar(sql));
                    //处理要移动的类别树后面的栏目的orderid,全部-(arr.Length+1)
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set orderid=orderid-"" + (arr.Length + 1) + "" where orderid>"" + last_orderid);
                }}
                else
                {{
                    last_orderid = orderid;
                    //处理要移动的类别树后面的栏目的orderid,全部-1
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set orderid=orderid-1 where orderid>"" + last_orderid);
                }}
                #endregion
                
                #region 处理目标类别的信息
                string target_parentpath = """";
                int target_orderid = 0,target_depth = 0, target_child = 0, target_last_orderid = 0;
                string target_rootid = string.Empty, target_previd = string.Empty, target_nextid = string.Empty, target_parentid = string.Empty, target_last_child_classid = string.Empty;
                string target_children = """";

                #region 是不是作为一级栏目
                if (!string.IsNullOrEmpty(target))
                {{
                    sql = ""select * from ["" + TableName + ""] where id='"" + target + ""'"";
                    dr = {0}.Database.ExecuteReader(System.Data.CommandType.Text,sql);
                    if (dr.Read())
                    {{
                        target_parentpath = dr[""parentpath""].ToString() + "","" + target;//新的父系路径
                        target_orderid = Convert.ToInt32(dr[""orderid""]);
                        target_rootid = Convert.ToString(dr[""rootid""]);
                        target_previd = Convert.ToString(dr[""previd""]);
                        target_nextid = Convert.ToString(dr[""nextid""]);
                        target_depth = Convert.ToInt32(dr[""depth""]);
                        target_parentid = Convert.ToString(dr[""parentid""]);
                        target_child = Convert.ToInt32(dr[""Child""]);
                    }}
                    dr.Close();
                    dr.Dispose();
                    //更新目标栏目的子栏目数目
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set Child=Child+1 where id='"" + target + ""'"");

                    target_children = GetChildren(target);
                    target_children = target_children.Replace(id, """");
                    for (int i = 0; i < arr.Length; i++)
                    {{
                        if (string.IsNullOrEmpty(arr[i])) {{ continue; }}
                        target_children = target_children.Replace(arr[i], """");
                    }}
                    target_children = target_children.Trim(',');

                    if (target_child > 0)
                    {{
                        //如果有子栏目找到最后一个子栏目的orderid
                        sql = ""select max(orderid) from ["" + TableName + ""] where id in ('"" + target_children.Replace("","",""','"") + ""')"";
                        target_last_orderid = Convert.ToInt32({0}.Database.ExecuteScalar(sql));
                        //找到目标类别的一级子类别最后一个id,并更新它的nextid=id
                        sql = ""select id from ["" + TableName + ""] where parentid='"" + target + ""' order by orderid desc"";
                        object temp_ = {0}.Database.ExecuteScalar(sql);
                        target_last_child_classid = Convert.ToString(temp_);
                        {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set nextid='"" + id + ""' where id='"" + target_last_child_classid + ""'"");
                    }}
                    else
                    {{
                        target_last_orderid = target_orderid;
                        target_last_child_classid = string.Empty;
                    }}
                    if (Child > 0)
                        //处理目标类别树后面的栏目的orderid,全部加上(arr.Length+1)
                        {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set orderid=orderid + "" + (arr.Length + 1) + "" where orderid>"" + target_last_orderid);
                    else
                        {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set orderid=orderid + 1 where orderid>"" + target_last_orderid);
                }}
                else//作为一级类别
                {{
                    //重新定义target_depth
                    target_depth = -1;
                    //重新定义target_last_orderid
                    if (Child > 0)
                        sql = ""select max(orderid) from ["" + TableName + ""] where id not in ('"" + (id + ""','"" + moveclassids.Replace("","",""','"")) + ""')"";
                    //_______________________________________________________________这里解决当要移动的栏目有子栏目的时候,orderid出现的小问题.
                    else
                        sql = ""select max(orderid) from ["" + TableName + ""] where id<>'"" + id + ""'"";//有可能要移动的类别在最后一个,这里把它排除
                    object _temp;
                    _temp = {0}.Database.ExecuteScalar(sql);
                    if (_temp != null)
                        target_last_orderid = Convert.ToInt32(_temp);
                    //重新定义target_rootid
                    target_rootid = id;

                    //得到previd
                    sql = ""select max(id) from ["" + TableName + ""] where parentid='' and id<>'"" + id + ""'"";
                    _temp = {0}.Database.ExecuteScalar(sql);
                    if (_temp != null)
                    {{
                        target_previd = Convert.ToString(_temp);
                        //修改上一个一级栏目的nextid
                        {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set nextid='"" + id + ""' where id='"" + target_previd + ""'"");
                    }}
                }}
                #endregion

                #endregion

                #region 综合处理

                if (Child > 0)//要移动的类别有子栏目
                {{
                    int depth_d = 0;//depth的减量
                    if (string.IsNullOrEmpty(target))
                        depth_d = depth;
                    else
                        depth_d = depth - (target_depth + 1);
                    //更新字栏目的父系路径为 target_parentpath + "","" + id ,orderid
                    for (int x = 0; x < arr.Length; x++)
                    {{
                        //注意这里要解决depth和parentpath的嵌套问题,即要移动的类别的子类别还有子类别
                        string path;
                        sql = ""select parentpath from ["" + TableName + ""] where id='"" + arr[x] + ""'"";
                        path = {0}.Database.ExecuteScalar(sql).ToString();
                        path = path.Replace((parentpath + "","" + id), (target_parentpath + "","" + id));
                        {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set depth=depth - "" + depth_d + "", parentpath='"" + path + ""',rootid='"" + target_rootid + ""',orderid="" + (target_last_orderid + x + 2) + "" where id='"" + arr[x] +""'"");
                        //__________________________________________________________________________________________________________________________________________________________//其父系栏目已经加1,这里至少加2
                    }}
                }}

                if (!string.IsNullOrEmpty(target))//更新要移动的类别的parentpath和previd,rootid,orderid,parentid,depth,nextid,target_previd
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set nextid='',depth="" + (target_depth + 1) + "",parentid='"" + target + ""', parentpath='"" + target_parentpath + ""',previd='"" + target_last_child_classid + ""' ,rootid='"" + target_rootid + ""',orderid="" + (target_last_orderid + 1) + "" where id ='"" + id +""'"");
                else//区别在于previd
                    {0}.Database.ExecuteNonQuery(dTran, System.Data.CommandType.Text,""update ["" + TableName + ""] set previd='"" + target_previd + ""',nextid='',depth="" + (target_depth + 1) + "",parentid='"" + target + ""', parentpath='"" + target_parentpath + ""' ,rootid='"" + target_rootid + ""',orderid="" + (target_last_orderid + 1) + "" where id ='"" + id +""'"");
                dTran.Commit();
                #endregion
            }}
            catch (Exception ex)
            {{
                rt= 4;
            }}
            finally
            {{
                dConn.Close();
            }}

            return rt;
";
            methodMoveClass.Statements.Add(new CodeSnippetStatement(string.Format(strTemp, dbsAnalysisClass.Name)));
            ctd1.Members.Add(methodMoveClass);
            #endregion 更改栏目路径
            


            //#region 根据id得到栏目名称
            ////getClassName
            //CodeMemberMethod MethodGetClassName = new CodeMemberMethod();
            //MethodGetClassName.Comments.Add(new CodeCommentStatement("<summary>", true));
            //MethodGetClassName.Comments.Add(new CodeCommentStatement("根据id得到栏目名称", true));
            //MethodGetClassName.Comments.Add(new CodeCommentStatement("</summary>", true));
            //MethodGetClassName.Comments.Add(new CodeCommentStatement("<param name=\"id\"></param>", true));
            //MethodGetClassName.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
            //MethodGetClassName.Name = "GetClassName";
            //MethodGetClassName.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //MethodGetClassName.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Int32), "id"));
            //MethodGetClassName.ReturnType = new CodeTypeReference(typeof(string));
            //MethodGetClassName.Statements.Add(new CodeSnippetExpression("return Select" + dbsAnalysisClass.Name + "(id).ClassName"));
            //ctd1.Members.Add(MethodGetClassName);
            //#endregion 根据id得到栏目名称
            

            
//            #region 显示列表的时候的repeater的itemcreated事件
//            //itemcreated
//            CodeMemberMethod MethodItemcreated = new CodeMemberMethod();
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<summary>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("显示列表的时候的repeater的itemcreated事件", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("</summary>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<param name=\"Sender\"></param>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<param name=\"e\"></param>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<param name=\"ctlname\"></param>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<param name=\"ctlname2\"></param>", true));
//            MethodItemcreated.Comments.Add(new CodeCommentStatement("<returns></returns>", true));
//            MethodItemcreated.Name = "Itemcreated";
//            MethodItemcreated.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//            MethodItemcreated.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "Sender"));
//            MethodItemcreated.Parameters.Add(new CodeParameterDeclarationExpression(typeof(System.Web.UI.WebControls.RepeaterItemEventArgs), "e"));
//            MethodItemcreated.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ctlname"));
//            MethodItemcreated.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ctlname2"));
//            strTemp = @"
//            System.Data.DataRowView dv = (System.Data.DataRowView)e.Item.DataItem;
//            int iDepth = Convert.ToInt32(dv[""Depth""]);
//            int NextID = Convert.ToInt32(dv[""NextID""]);
//            int Child = Convert.ToInt32(dv[""Child""]);
//
//            try
//            {{
//                showLine[iDepth] = Convert.ToInt32(dv[""NextID""]) > 0 ? true : false;//这个值是经常被修改的.
//            }}
//            catch (Exception ex)
//            {{
//                showLine.Add(false);
//                showLine[iDepth] = Convert.ToInt32(dv[""NextID""]) > 0 ? true : false;//这个值是经常被修改的.
//            }}
//
//            System.Web.UI.WebControls.Literal l = new System.Web.UI.WebControls.Literal();
//            l = (System.Web.UI.WebControls.Literal)e.Item.FindControl(ctlname);
//            string text = """";
//            string text2 = """";
//
//            if (iDepth > 0)
//            {{
//                for (int i = 1; i <= iDepth; i++)
//                {{
//                    if (i == iDepth)
//                    {{
//                        if (NextID > 0)
//                            text += ""<img src='images/tree_line1.gif' width='17' height='16' valign='abvmiddle'>"";
//                        else
//                            text += ""<img src='images/tree_line2.gif' width='17' height='16' valign='abvmiddle'>"";
//                    }}
//                    else//这个判断主要是看iDepth以前的要显示|,还是显示空填充
//                    {{
//                        if ((bool)showLine[i])
//                            text += ""<img src='images/tree_line3.gif' width='17' height='16' valign='abvmiddle'>"";
//                        else
//                            text += ""<img src='images/tree_line4.gif' width='17' height='16' valign='abvmiddle'>"";
//                    }}
//                }}
//            }}
//
//            if (Child > 0)
//            {{
//                text2 = ""（"" + Child + ""）"";//()里的数字,表示子栏目数目
//                text += ""<img src='Images/tree_folder4.gif' width='15' height='15' valign='abvmiddle'>"";
//            }}
//            else
//                text += ""<img src='Images/tree_folder3.gif' width='15' height='15' valign='abvmiddle'>"";
//
//            l.Text = text;
//
//            System.Web.UI.WebControls.Literal l2 = (System.Web.UI.WebControls.Literal)e.Item.FindControl(ctlname2);
//            l2.Text = text2;
//";
//            MethodItemcreated.Statements.Add(new CodeSnippetExpression(string.Format(strTemp, dbsAnalysisClass.Name)));
//            ctd1.Members.Add(MethodItemcreated);
//            #endregion 显示列表的时候的repeater的itemcreated事件
    
            dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctd1);
            #endregion
            
            

            #region  CatalogHierarchyData
            #region 生成类
            CodeTypeDeclaration ctd2 = new CodeTypeDeclaration(dbsAnalysisClass.Name + "HierarchyData");//生成类
            ctd2.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctd2.Comments.Add(new CodeCommentStatement(" Copyright (C) " + System.DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 文件功能描述：  " + dbsAnalysisClass.Name + "的 IHierarchyData 类", false));
            ctd2.Comments.Add(new CodeCommentStatement("", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctd2.Comments.Add(new CodeCommentStatement("", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd2.Comments.Add(new CodeCommentStatement("", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd2.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd2.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            ctd2.IsClass = true;
            ctd2.Attributes = MemberAttributes.Public;
            ctd2.BaseTypes.Add(typeof(System.Web.UI.IHierarchyData));
            //生成类注释
            ctd2.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctd2.Comments.Add(new CodeCommentStatement(dbsAnalysisClass.Name + "的 IHierarchyData 类", true));
            ctd2.Comments.Add(new CodeCommentStatement("</summary>", true));


            //ctd2.Members.Add(new CodeMemberField(dbsAnalysisClass.Name+Config.DB_CLASS, "obj=null"));

            #endregion

            #region 构造函数
            //参数构造函数
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;
            constructor.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "HierarchyData 的构造函数", true));
            constructor.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor.Name = dbsAnalysisClass.Name + "HierarchyData";
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(dbsAnalysisClass.Name, "obj"));
            constructor.Statements.Add(new CodeSnippetExpression("this.catalogObject = obj"));
            ctd2.Members.Add(constructor);
            #endregion 构造函数
            #region 生成类字段

            //生成类的 私有字段
            CodeMemberField FieldcatalogObject = new CodeMemberField();
            FieldcatalogObject.Attributes = MemberAttributes.Private;
            FieldcatalogObject.Type = new CodeTypeReference(dbsAnalysisClass.Name);
            FieldcatalogObject.Name = "catalogObject= null";
            ctd2.Members.Add(FieldcatalogObject);
            #endregion
            #region 生成 属性
            foreach (MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property var in _modelField)
            {
                //生成类的属性注释 和 属性
                CodeMemberProperty cmp = new CodeMemberProperty();
                cmp.Comments.Add(new CodeCommentStatement("<summary>", true));
                cmp.Comments.Add(new CodeCommentStatement(var.Summary, true));
                cmp.Comments.Add(new CodeCommentStatement("</summary>", true));
                cmp.Attributes = MemberAttributes.Public;
                cmp.Type = new CodeTypeReference(var.Type);
                cmp.Name = var.Name;
                cmp.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "catalogObject." + var.Name)));
                cmp.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "catalogObject." + var.Name), new CodePropertySetValueReferenceExpression()));
                ctd2.Members.Add(cmp);
            }

            #endregion
            #region IHierarchyData 接口
            //HasChildren
            CodeMemberProperty PropertyHasChildren = new CodeMemberProperty();
            PropertyHasChildren.Attributes = MemberAttributes.Public;
            PropertyHasChildren.Type = new CodeTypeReference("System.Boolean");
            PropertyHasChildren.Name = "HasChildren";
            PropertyHasChildren.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "catalogObject.Child != 0")));
            ctd2.Members.Add(PropertyHasChildren);
            //Item
            CodeMemberProperty PropertyItem = new CodeMemberProperty();
            PropertyItem.Attributes = MemberAttributes.Public;
            PropertyItem.Type = new CodeTypeReference("System.Object");
            PropertyItem.Name = "Item";
            PropertyItem.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "catalogObject")));
            ctd2.Members.Add(PropertyItem);
            //Path
            CodeMemberProperty PropertyPath = new CodeMemberProperty();
            PropertyPath.Attributes = MemberAttributes.Public;
            PropertyPath.Type = new CodeTypeReference(typeof(string));
            PropertyPath.Name = "Path";
            PropertyPath.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "catalogObject.parentPath")));
            ctd2.Members.Add(PropertyPath);
            //Type
            CodeMemberProperty PropertyType = new CodeMemberProperty();
            PropertyType.Attributes = MemberAttributes.Public;
            PropertyType.Type = new CodeTypeReference(typeof(string));
            PropertyType.Name = "Type";
            PropertyType.GetStatements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("\"catalogObject\"")));
            ctd2.Members.Add(PropertyType);
            //ToString
            CodeMemberMethod MethodToString = new CodeMemberMethod();
            MethodToString.Name = "ToString";
            MethodToString.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            MethodToString.ReturnType = new CodeTypeReference(typeof(string));
            MethodToString.Statements.Add(new CodeSnippetExpression("return catalogObject.ToString()"));
            ctd2.Members.Add(MethodToString);
            //GetParent
            CodeMemberMethod MethodGetParent = new CodeMemberMethod();
            MethodGetParent.Name = "GetParent";
            MethodGetParent.Attributes = MemberAttributes.Public;
            MethodGetParent.ReturnType = new CodeTypeReference(typeof(System.Web.UI.IHierarchyData));
            MethodGetParent.Statements.Add(new CodeSnippetExpression("return new " + dbsAnalysisClass.Name + "HierarchyData(" + dbsAnalysisClass.Name + "." + string.Format(Config.DbMemberMethodGet, dbsAnalysisClass.Name) + "(catalogObject.ParentID))"));
            ctd2.Members.Add(MethodGetParent);
            //GetChildren
            CodeMemberMethod MethodGetChildren1 = new CodeMemberMethod();
            MethodGetChildren1.Name = "GetChildren";
            MethodGetChildren1.Attributes = MemberAttributes.Public;
            MethodGetChildren1.ReturnType = new CodeTypeReference(typeof(System.Web.UI.IHierarchicalEnumerable));
            MethodGetChildren1.Statements.Add(new CodeSnippetExpression(dbsAnalysisClass.Name + "HierarchicalEnumerable children = new " + dbsAnalysisClass.Name + "HierarchicalEnumerable()"));
            MethodGetChildren1.Statements.Add(new CodeSnippetStatement("foreach (" + dbsAnalysisClass.Name + " cg in " + dbsAnalysisClass.Name + ".GetChild(catalogObject.Id)){"));
            MethodGetChildren1.Statements.Add(new CodeSnippetExpression("children.Add(new " + dbsAnalysisClass.Name + "HierarchyData(cg))"));
            MethodGetChildren1.Statements.Add(new CodeSnippetStatement("}"));
            MethodGetChildren1.Statements.Add(new CodeSnippetExpression("return children"));
            ctd2.Members.Add(MethodGetChildren1);

            #endregion
            dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctd2);
            #endregion

            #region  CatalogHierarchicalEnumerable
            #region 生成类
            CodeTypeDeclaration ctd3 = new CodeTypeDeclaration(dbsAnalysisClass.Name + "HierarchicalEnumerable");//生成类
            ctd3.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctd3.Comments.Add(new CodeCommentStatement(" Copyright (C) " + System.DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 文件功能描述：  " + dbsAnalysisClass.Name + "的 HierarchicalEnumerable 类", false));
            ctd3.Comments.Add(new CodeCommentStatement("", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctd3.Comments.Add(new CodeCommentStatement("", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd3.Comments.Add(new CodeCommentStatement("", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd3.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd3.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            ctd3.IsClass = true;
            ctd3.Attributes = MemberAttributes.Public;
            ctd3.BaseTypes.Add(typeof(System.Collections.ArrayList));
            ctd3.BaseTypes.Add(typeof(System.Web.UI.IHierarchicalEnumerable));
            //生成类注释
            ctd3.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctd3.Comments.Add(new CodeCommentStatement(dbsAnalysisClass.Name + "的 HierarchicalEnumerable 类", true));
            ctd3.Comments.Add(new CodeCommentStatement("</summary>", true));


            //ctd3.Members.Add(new CodeMemberField(dbsAnalysisClass.Name+Config.DB_CLASS, "obj=null"));

            #endregion
            #region 构造函数
            //参数构造函数
            CodeConstructor constructor1 = new CodeConstructor();
            constructor1.Attributes = MemberAttributes.Public;
            constructor1.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor1.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "HierarchicalEnumerable 的构造函数", true));
            constructor1.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor1.Name = dbsAnalysisClass.Name + "HierarchicalEnumerable";
            ctd3.Members.Add(constructor1);
            #endregion 构造函数

            #region IHierarchicalEnumerable 接口
            //GetHierarchyData
            CodeMemberMethod MethodGetHierarchyData = new CodeMemberMethod();
            MethodGetHierarchyData.Name = "GetHierarchyData";
            MethodGetHierarchyData.Attributes = MemberAttributes.Public;
            MethodGetHierarchyData.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "enumeratedItem"));
            MethodGetHierarchyData.ReturnType = new CodeTypeReference(typeof(System.Web.UI.IHierarchyData));
            MethodGetHierarchyData.Statements.Add(new CodeSnippetExpression("return enumeratedItem as System.Web.UI.IHierarchyData"));
            ctd3.Members.Add(MethodGetHierarchyData);

            #endregion
            dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctd3);
            #endregion

            #region  CatalogDataSourceView
            #region 生成类
            CodeTypeDeclaration ctd4 = new CodeTypeDeclaration(dbsAnalysisClass.Name + "DataSourceView");//生成类
            ctd4.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctd4.Comments.Add(new CodeCommentStatement(" Copyright (C) " + System.DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 文件功能描述：  " + dbsAnalysisClass.Name + "的 DataSourceView 类", false));
            ctd4.Comments.Add(new CodeCommentStatement("", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctd4.Comments.Add(new CodeCommentStatement("", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd4.Comments.Add(new CodeCommentStatement("", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd4.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd4.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            ctd4.IsClass = true;
            ctd4.Attributes = MemberAttributes.Public;
            ctd4.BaseTypes.Add(typeof(System.Web.UI.HierarchicalDataSourceView));
            //生成类注释
            ctd4.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctd4.Comments.Add(new CodeCommentStatement(dbsAnalysisClass.Name + "的 DataSourceView 类", true));
            ctd4.Comments.Add(new CodeCommentStatement("</summary>", true));


            //ctd4.Members.Add(new CodeMemberField(dbsAnalysisClass.Name+Config.DB_CLASS, "obj=null"));

            #endregion
            #region 构造函数
            //参数构造函数
            CodeConstructor constructor2 = new CodeConstructor();
            constructor2.Attributes = MemberAttributes.Public;
            constructor2.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor2.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "DataSourceView 的构造函数", true));
            constructor2.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor2.Name = dbsAnalysisClass.Name + "DataSourceView";
            ctd4.Members.Add(constructor2);
            CodeConstructor constructor2_1 = new CodeConstructor();
            constructor2_1.Attributes = MemberAttributes.Public;
            constructor2_1.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor2_1.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "DataSourceView 的构造函数", true));
            constructor2_1.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor2_1.Name = dbsAnalysisClass.Name + "DataSourceView";
            constructor2_1.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "viewPath"));
            constructor2_1.Statements.Add(new CodeSnippetExpression("this._viewPath = viewPath"));
            ctd4.Members.Add(constructor2_1);

            CodeConstructor constructor2_2 = new CodeConstructor();
            constructor2_2.Attributes = MemberAttributes.Public;
            constructor2_2.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor2_2.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "DataSourceView 的构造函数", true));
            constructor2_2.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor2_2.Name = dbsAnalysisClass.Name + "DataSourceView";
            constructor2_2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "viewPath"));
            constructor2_2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            constructor2_2.Statements.Add(new CodeSnippetExpression("this._viewPath = viewPath"));
            constructor2_2.Statements.Add(new CodeSnippetExpression("this._id = id"));


            ctd4.Members.Add(constructor2_2);
            CodeConstructor constructor2_3 = new CodeConstructor();
            constructor2_3.Attributes = MemberAttributes.Public;
            constructor2_3.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor2_3.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "DataSourceView 的构造函数", true));
            constructor2_3.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor2_3.Name = dbsAnalysisClass.Name + "DataSourceView";
            constructor2_3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "viewPath"));
            constructor2_3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ClassName"));
            constructor2_3.Statements.Add(new CodeSnippetExpression("this._viewPath = viewPath"));
            constructor2_3.Statements.Add(new CodeSnippetExpression("this._classname = ClassName"));

            //ctd4.Members.Add(constructor2_3);
            #endregion 构造函数
            #region 生成类字段

            //生成类的 私有字段
            //_viewPath
            CodeMemberField Field_viewPath = new CodeMemberField();
            Field_viewPath.Attributes = MemberAttributes.Private;
            Field_viewPath.Type = new CodeTypeReference(typeof(string));
            Field_viewPath.Name = "_viewPath";
            ctd4.Members.Add(Field_viewPath);

            for (int i = 0; i < _modelField.Count; i++)
            {
                CodeMemberField field = new CodeMemberField();
                field.Attributes = MemberAttributes.Private;
                field.Type = new CodeTypeReference(_modelField[i].Type);
                field.Name = "_" + _modelField[i].Name.ToLower() + " = " + _modelField[i].Type.Replace("System.", "System.Convert.To") + "(\"" + _modelField[i].Value + "\")";
                ctd4.Members.Add(field);

            }



            ////_classname
            //CodeMemberField Field_classname = new CodeMemberField();
            //Field_classname.Attributes = MemberAttributes.Private;
            //Field_classname.Type = new CodeTypeReference(typeof(string));
            //Field_classname.Name = "_classname=\"\"";
            //ctd4.Members.Add(Field_classname);
            ////_id
            //CodeMemberField Field_classid = new CodeMemberField();
            //Field_classid.Attributes = MemberAttributes.Private;
            //Field_classid.Type = new CodeTypeReference(typeof(Int32));
            //Field_classid.Name = "_id=0";
            //ctd4.Members.Add(Field_classid);
            #endregion
            #region 生成 属性
            for (int i = 0; i < _modelField.Count; i++)
            {
                CodeMemberProperty propertyModel = new CodeMemberProperty();
                propertyModel.Comments.Add(new CodeCommentStatement("<summary>", true));
                propertyModel.Comments.Add(new CodeCommentStatement(_modelField[i].Summary, true));
                propertyModel.Comments.Add(new CodeCommentStatement("</summary>", true));
                propertyModel.Attributes = MemberAttributes.Public;
                propertyModel.Type = new CodeTypeReference(_modelField[i].Type);
                propertyModel.Name = _modelField[i].Name;
                propertyModel.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower())));
                propertyModel.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower()), new CodePropertySetValueReferenceExpression()));
                ctd4.Members.Add(propertyModel);
            }
            ////ClassName
            //CodeMemberProperty PropertyClassName = new CodeMemberProperty();
            //PropertyClassName.Comments.Add(new CodeCommentStatement("<summary>", true));
            //PropertyClassName.Comments.Add(new CodeCommentStatement("栏目名称", true));
            //PropertyClassName.Comments.Add(new CodeCommentStatement("</summary>", true));
            //PropertyClassName.Attributes = MemberAttributes.Public;
            //PropertyClassName.Type = new CodeTypeReference(typeof(string));
            //PropertyClassName.Name = "ClassName";
            //PropertyClassName.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname")));
            //PropertyClassName.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname"), new CodePropertySetValueReferenceExpression()));
            //ctd4.Members.Add(PropertyClassName);
            ////id
            //CodeMemberProperty Propertyid = new CodeMemberProperty();
            //Propertyid.Comments.Add(new CodeCommentStatement("<summary>", true));
            //Propertyid.Comments.Add(new CodeCommentStatement("栏目id", true));
            //Propertyid.Comments.Add(new CodeCommentStatement("</summary>", true));
            //Propertyid.Attributes = MemberAttributes.Public;
            //Propertyid.Type = new CodeTypeReference(typeof(Int32));
            //Propertyid.Name = "id";
            //Propertyid.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id")));
            //Propertyid.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id"), new CodePropertySetValueReferenceExpression()));
            //ctd4.Members.Add(Propertyid);
            #endregion

            #region HierarchicalDataSourceView 接口
            //Select
            CodeMemberMethod methodSelect = new CodeMemberMethod();
            methodSelect.Name = "Select";
            methodSelect.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            methodSelect.ReturnType = new CodeTypeReference(typeof(System.Web.UI.IHierarchicalEnumerable));
            methodSelect.Statements.Add(new CodeSnippetExpression(dbsAnalysisClass.Name + "HierarchicalEnumerable clhe = new " + dbsAnalysisClass.Name + "HierarchicalEnumerable()"));
            methodSelect.Statements.Add(new CodeSnippetStatement("foreach (" + dbsAnalysisClass.Name + " cg in " + dbsAnalysisClass.Name + ".GetChild(_id)){"));
            methodSelect.Statements.Add(new CodeSnippetExpression("clhe.Add(new " + dbsAnalysisClass.Name + "HierarchyData(cg))"));
            methodSelect.Statements.Add(new CodeSnippetStatement("}"));
            methodSelect.Statements.Add(new CodeSnippetExpression("return clhe"));
            ctd4.Members.Add(methodSelect);
            #endregion
            dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctd4);
            #endregion

            #region  CatalogDataSource
            #region 生成类
            CodeTypeDeclaration ctd5 = new CodeTypeDeclaration(dbsAnalysisClass.Name + "DataSource");//生成类
            ctd5.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctd5.Comments.Add(new CodeCommentStatement(" Copyright (C) " + System.DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 文件功能描述：  " + dbsAnalysisClass.Name + "的 DataSource 类", false));
            ctd5.Comments.Add(new CodeCommentStatement("", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctd5.Comments.Add(new CodeCommentStatement("", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd5.Comments.Add(new CodeCommentStatement("", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctd5.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctd5.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            ctd5.IsClass = true;
            ctd5.Attributes = MemberAttributes.Public;
            ctd5.BaseTypes.Add(typeof(System.Web.UI.HierarchicalDataSourceControl));
            ctd5.BaseTypes.Add(typeof(System.Web.UI.IHierarchicalDataSource));
            ctd5.CustomAttributes.Add(new CodeAttributeDeclaration("System.Web.AspNetHostingPermission", new CodeAttributeArgument(new CodeSnippetExpression("System.Security.Permissions.SecurityAction.Demand,Level = System.Web.AspNetHostingPermissionLevel.Minimal"))));// "System.Security.Permissions.SecurityAction.Demand", "Level = System.Web.AspNetHostingPermissionLevel.Minimal"));
            //生成类注释
            ctd5.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctd5.Comments.Add(new CodeCommentStatement(dbsAnalysisClass.Name + "的 DataSource 类", true));
            ctd5.Comments.Add(new CodeCommentStatement("</summary>", true));


            //ctd5.Members.Add(new CodeMemberField(dbsAnalysisClass.Name+Config.DB_CLASS, "obj=null"));

            #endregion
            #region 构造函数
            //参数构造函数
            CodeConstructor constructor3 = new CodeConstructor();
            constructor3.Attributes = MemberAttributes.Public;
            constructor3.Comments.Add(new CodeCommentStatement("<summary>", true));
            constructor3.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "DataSource 的构造函数", true));
            constructor3.Comments.Add(new CodeCommentStatement("</summary>", true));
            constructor3.Name = dbsAnalysisClass.Name + "DataSource";
            ctd5.Members.Add(constructor3);

            #endregion 构造函数
            #region 生成类字段

            //生成类的 私有字段
            //view
            CodeMemberField Fieldview = new CodeMemberField();
            Fieldview.Attributes = MemberAttributes.Private;
            Fieldview.Type = new CodeTypeReference(dbsAnalysisClass.Name + "DataSourceView");
            Fieldview.Name = "view=null";
            ctd5.Members.Add(Fieldview);

            for (int i = 0; i < _modelField.Count; i++)
            {
                CodeMemberField field = new CodeMemberField();
                field.Attributes = MemberAttributes.Private;
                field.Type = new CodeTypeReference(_modelField[i].Type);
                field.Name = "_" + _modelField[i].Name.ToLower() + " = " + _modelField[i].Type.Replace("System.", "System.Convert.To") + "(\"" + _modelField[i].Value + "\")";
                ctd5.Members.Add(field);
            }
            ////_classname
            ////CodeMemberField Field_classname = new CodeMemberField();
            ////Field_classname.Attributes = MemberAttributes.Private;
            ////Field_classname.Type = new CodeTypeReference(typeof(string));
            ////Field_classname.Name = "_classname=\"\"";
            //ctd5.Members.Add(Field_classname);
            ////_classid
            ////CodeMemberField Field_classid = new CodeMemberField();
            ////Field_classid.Attributes = MemberAttributes.Private;
            ////Field_classid.Type = new CodeTypeReference(typeof(Int32));
            ////Field_classid.Name = "_classid=0";
            //ctd5.Members.Add(Field_classid);
            #endregion
            #region 生成 属性
            for (int i = 0; i < _modelField.Count; i++)
            {
                CodeMemberProperty propertyModel = new CodeMemberProperty();
                propertyModel.Comments.Add(new CodeCommentStatement("<summary>", true));
                propertyModel.Comments.Add(new CodeCommentStatement(_modelField[i].Summary, true));
                propertyModel.Comments.Add(new CodeCommentStatement("</summary>", true));
                propertyModel.Attributes = MemberAttributes.Public;
                propertyModel.Type = new CodeTypeReference(_modelField[i].Type);
                propertyModel.Name = _modelField[i].Name;
                propertyModel.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower())));
                propertyModel.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower()), new CodePropertySetValueReferenceExpression()));
                ctd5.Members.Add(propertyModel);
            }
            ////ClassName
            //CodeMemberProperty PropertyClassName = new CodeMemberProperty();
            //PropertyClassName.Comments.Add(new CodeCommentStatement("<summary>", true));
            //PropertyClassName.Comments.Add(new CodeCommentStatement("栏目名称", true));
            //PropertyClassName.Comments.Add(new CodeCommentStatement("</summary>", true));
            //PropertyClassName.Attributes = MemberAttributes.Public;
            //PropertyClassName.Type = new CodeTypeReference(typeof(string));
            //PropertyClassName.Name = "ClassName";
            //PropertyClassName.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname")));
            //PropertyClassName.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname"), new CodePropertySetValueReferenceExpression()));
            //ctd4.Members.Add(PropertyClassName);
            ////id
            //CodeMemberProperty Propertyid = new CodeMemberProperty();
            //Propertyid.Comments.Add(new CodeCommentStatement("<summary>", true));
            //Propertyid.Comments.Add(new CodeCommentStatement("栏目id", true));
            //Propertyid.Comments.Add(new CodeCommentStatement("</summary>", true));
            //Propertyid.Attributes = MemberAttributes.Public;
            //Propertyid.Type = new CodeTypeReference(typeof(Int32));
            //Propertyid.Name = "id";
            //Propertyid.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id")));
            //Propertyid.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id"), new CodePropertySetValueReferenceExpression()));
            //ctd4.Members.Add(Propertyid);
            #endregion

            #region 方法
            //select1
            CodeMemberMethod methodSelect1 = new CodeMemberMethod();
            methodSelect1.Name = "Select";
            methodSelect1.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodSelect1.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
            methodSelect1.Statements.Add(new CodeSnippetExpression("return new " + dbsAnalysisClass.Name + "DataSource()"));
            ctd5.Members.Add(methodSelect1);
            //select2
            CodeMemberMethod methodSelect2 = new CodeMemberMethod();
            methodSelect2.Name = "Select";
            methodSelect2.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodSelect2.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
            methodSelect2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            methodSelect2.Statements.Add(new CodeSnippetExpression(dbsAnalysisClass.Name + "DataSource cds = new " + dbsAnalysisClass.Name + "DataSource()"));
            methodSelect2.Statements.Add(new CodeSnippetExpression("cds._id = id"));
            methodSelect2.Statements.Add(new CodeSnippetExpression("return cds"));
            ctd5.Members.Add(methodSelect2);
            ////select3
            //CodeMemberMethod methodSelect3 = new CodeMemberMethod();
            //methodSelect3.Name = "Select";
            //methodSelect3.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //methodSelect3.ReturnType = new CodeTypeReference(dbsAnalysisClass.Name + "DataSource");
            //methodSelect3.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "ClassName"));
            //methodSelect3.Statements.Add(new CodeSnippetExpression(dbsAnalysisClass.Name + "DataSource cds = new " + dbsAnalysisClass.Name + "DataSource()"));
            //methodSelect3.Statements.Add(new CodeSnippetExpression("cds._classname = ClassName"));
            //methodSelect3.Statements.Add(new CodeSnippetExpression("return cds"));
            //ctd5.Members.Add(methodSelect3);
            //CreateControlCollection
            CodeMemberMethod methodCreateControlCollection = new CodeMemberMethod();
            methodCreateControlCollection.Name = "CreateControlCollection";
            methodCreateControlCollection.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            methodCreateControlCollection.ReturnType = new CodeTypeReference(typeof(System.Web.UI.ControlCollection));
            methodCreateControlCollection.Statements.Add(new CodeSnippetExpression("return new System.Web.UI.ControlCollection(this)"));
            ctd5.Members.Add(methodCreateControlCollection);
            //GetHierarchicalView
            CodeMemberMethod methodGetHierarchicalView = new CodeMemberMethod();
            methodGetHierarchicalView.Name = "GetHierarchicalView";
            methodGetHierarchicalView.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            methodGetHierarchicalView.ReturnType = new CodeTypeReference(typeof(System.Web.UI.HierarchicalDataSourceView));
            methodGetHierarchicalView.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "viewPath"));
            methodGetHierarchicalView.Statements.Add(new CodeSnippetStatement("if (null == view){"));
            methodGetHierarchicalView.Statements.Add(new CodeSnippetExpression("view = new " + dbsAnalysisClass.Name + "DataSourceView(viewPath)"));
            for (int i = 0; i < _modelField.Count; i++)
            {
                methodGetHierarchicalView.Statements.Add(new CodeSnippetExpression("view." + _modelField[i].Name + " = this._" + _modelField[i].Name.ToLower()));
            }
            //MethodGetHierarchicalView.Statements.Add(new CodeSnippetExpression("view.Id = this._id"));
            //MethodGetHierarchicalView.Statements.Add(new CodeSnippetExpression("view.ClassName = _classname"));
            methodGetHierarchicalView.Statements.Add(new CodeSnippetStatement("}"));
            methodGetHierarchicalView.Statements.Add(new CodeSnippetExpression("return view"));
            ctd5.Members.Add(methodGetHierarchicalView);
            #endregion
            dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctd5);
            #endregion











            //禁运
            //#region  CatalogListItem
            //#region 生成类
            //CodeTypeDeclaration ctd6 = new CodeTypeDeclaration(dbsAnalysisClass.Name + "ListItem");//生成类
            //ctd6.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" Copyright (C) " + System.DateTime.Today.Year + "  毛才君 版权所有。", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 文件功能描述：  " + dbsAnalysisClass.Name + "的 ListItem 类", false));
            //ctd6.Comments.Add(new CodeCommentStatement("", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            //ctd6.Comments.Add(new CodeCommentStatement("", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            //ctd6.Comments.Add(new CodeCommentStatement("", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            //ctd6.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            //ctd6.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));

            //ctd6.IsClass = true;
            //ctd6.Attributes = MemberAttributes.Public;
            //ctd6.BaseTypes.Add(typeof(System.Web.UI.WebControls.ListItem));
            ////生成类注释
            //ctd6.Comments.Add(new CodeCommentStatement("<summary>", true));
            //ctd6.Comments.Add(new CodeCommentStatement(dbsAnalysisClass.Name + "的 ListItem 类", true));
            //ctd6.Comments.Add(new CodeCommentStatement("</summary>", true));
            //#endregion
            //#region 构造函数
            ////参数构造函数
            //CodeConstructor constructor4 = new CodeConstructor();
            //constructor4.Attributes = MemberAttributes.Public;
            //constructor4.Comments.Add(new CodeCommentStatement("<summary>", true));
            //constructor4.Comments.Add(new CodeCommentStatement("类" + dbsAnalysisClass.Name + "ListItem 的构造函数", true));
            //constructor4.Comments.Add(new CodeCommentStatement("</summary>", true));
            //constructor4.Name = dbsAnalysisClass.Name + "ListItem";
            //ctd6.Members.Add(constructor4);

            //#endregion 构造函数
            ////#region 生成类字段

            //////生成类的 私有字段
            //////_viewPath
            ////CodeMemberField Field_viewPath = new CodeMemberField();
            ////Field_viewPath.Attributes = MemberAttributes.Private;
            ////Field_viewPath.Type = new CodeTypeReference(typeof(string));
            ////Field_viewPath.Name = "_viewPath";
            ////ctd4.Members.Add(Field_viewPath);

            ////for (int i = 0; i < _modelField.Count; i++)
            ////{
            ////    CodeMemberField field = new CodeMemberField();
            ////    field.Attributes = MemberAttributes.Private;
            ////    field.Type = new CodeTypeReference(_modelField[i].Type);
            ////    field.Name = "_" + _modelField[i].Name.ToLower();
            ////    ctd4.Members.Add(field);
            ////}



            ////////_classname
            //////CodeMemberField Field_classname = new CodeMemberField();
            //////Field_classname.Attributes = MemberAttributes.Private;
            //////Field_classname.Type = new CodeTypeReference(typeof(string));
            //////Field_classname.Name = "_classname=\"\"";
            //////ctd4.Members.Add(Field_classname);
            ////////_id
            //////CodeMemberField Field_classid = new CodeMemberField();
            //////Field_classid.Attributes = MemberAttributes.Private;
            //////Field_classid.Type = new CodeTypeReference(typeof(Int32));
            //////Field_classid.Name = "_id=0";
            //////ctd4.Members.Add(Field_classid);
            ////#endregion
            ////#region 生成 属性
            ////for (int i = 0; i < _modelField.Count; i++)
            ////{
            ////    CodeMemberProperty PropertyModel = new CodeMemberProperty();
            ////    PropertyModel.Comments.Add(new CodeCommentStatement("<summary>", true));
            ////    PropertyModel.Comments.Add(new CodeCommentStatement(_modelField[i].Summary, true));
            ////    PropertyModel.Comments.Add(new CodeCommentStatement("</summary>", true));
            ////    PropertyModel.Attributes = MemberAttributes.Public;
            ////    PropertyModel.Type = new CodeTypeReference(_modelField[i].Type);
            ////    PropertyModel.Name = _modelField[i].Name;
            ////    PropertyModel.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower())));
            ////    PropertyModel.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + _modelField[i].Name.ToLower()), new CodePropertySetValueReferenceExpression()));
            ////    ctd4.Members.Add(PropertyModel);
            ////}
            ////////ClassName
            //////CodeMemberProperty PropertyClassName = new CodeMemberProperty();
            //////PropertyClassName.Comments.Add(new CodeCommentStatement("<summary>", true));
            //////PropertyClassName.Comments.Add(new CodeCommentStatement("栏目名称", true));
            //////PropertyClassName.Comments.Add(new CodeCommentStatement("</summary>", true));
            //////PropertyClassName.Attributes = MemberAttributes.Public;
            //////PropertyClassName.Type = new CodeTypeReference(typeof(string));
            //////PropertyClassName.Name = "ClassName";
            //////PropertyClassName.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname")));
            //////PropertyClassName.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_classname"), new CodePropertySetValueReferenceExpression()));
            //////ctd4.Members.Add(PropertyClassName);
            ////////id
            //////CodeMemberProperty Propertyid = new CodeMemberProperty();
            //////Propertyid.Comments.Add(new CodeCommentStatement("<summary>", true));
            //////Propertyid.Comments.Add(new CodeCommentStatement("栏目id", true));
            //////Propertyid.Comments.Add(new CodeCommentStatement("</summary>", true));
            //////Propertyid.Attributes = MemberAttributes.Public;
            //////Propertyid.Type = new CodeTypeReference(typeof(Int32));
            //////Propertyid.Name = "id";
            //////Propertyid.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id")));
            //////Propertyid.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_id"), new CodePropertySetValueReferenceExpression()));
            //////ctd4.Members.Add(Propertyid);
            ////#endregion


            //Namespace.Types.Add(ctd6);
            //#endregion

        }

        private void ReturnType(CodeTypeDeclaration ctd1)
        {
            #region ReturnType
            CodeTypeDeclaration ctdReturnType = new CodeTypeDeclaration("ReturnType");//ReturnType
            ctdReturnType.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" Copyright (C) " + DateTime.Today.Year + "  毛才君 版权所有。", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 文件编号：      ", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 文 件 名：      ", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 文件功能描述：  无限分类 " + ctd1.Name + " 的反回值", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement("", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 创建标识：      毛才君    " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement("", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement("", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 修改标识：", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement(" 修改描述：", false));
            ctdReturnType.Comments.Add(new CodeCommentStatement("----------------------------------------------------------------------------------------", false));
            ctdReturnType.IsEnum = true;
            ctdReturnType.Attributes = MemberAttributes.Public;
            //生成类注释
            ctdReturnType.Comments.Add(new CodeCommentStatement("<summary>", true));
            ctdReturnType.Comments.Add(new CodeCommentStatement("无限分类 " + ctd1.Name + " 的反回值", true));
            ctdReturnType.Comments.Add(new CodeCommentStatement("</summary>", true));
            #region OK
            CodeMemberField cmfOK = new CodeMemberField();
            cmfOK.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfOK.Comments.Add(new CodeCommentStatement("表示成功", true));
            cmfOK.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfOK.Name = "OK";
            ctdReturnType.Members.Add(cmfOK);
            #endregion OK
            #region Repeat
            CodeMemberField cmfRepeat = new CodeMemberField();
            cmfRepeat.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfRepeat.Comments.Add(new CodeCommentStatement("表示有重复的项目ID", true));
            cmfRepeat.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfRepeat.Name = "Repeat";
            ctdReturnType.Members.Add(cmfRepeat);
            #endregion Repeat
            #region NoParent
            CodeMemberField cmfNoParent = new CodeMemberField();
            cmfNoParent.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfNoParent.Comments.Add(new CodeCommentStatement("表示所属类别不存在", true));
            cmfNoParent.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfNoParent.Name = "NoParent";
            ctdReturnType.Members.Add(cmfNoParent);
            #endregion NoParent
            #region HaveChild
            CodeMemberField cmfHaveChild = new CodeMemberField();
            cmfHaveChild.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfHaveChild.Comments.Add(new CodeCommentStatement("表示所属类别不存在", true));
            cmfHaveChild.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfHaveChild.Name = "HaveChild";
            ctdReturnType.Members.Add(cmfHaveChild);
            #endregion HaveChild
            #region NoItem
            CodeMemberField cmfNoItem = new CodeMemberField();
            cmfNoItem.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfNoItem.Comments.Add(new CodeCommentStatement("表示所属类别不存在", true));
            cmfNoItem.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfNoItem.Name = "NoItem";
            ctdReturnType.Members.Add(cmfNoItem);
            #endregion NoItem
            #region Err
            CodeMemberField cmfErr = new CodeMemberField();
            cmfErr.Comments.Add(new CodeCommentStatement("<summary>", true));
            cmfErr.Comments.Add(new CodeCommentStatement("其他错误", true));
            cmfErr.Comments.Add(new CodeCommentStatement("</summary>", true));
            cmfErr.Name = "Err";
            ctdReturnType.Members.Add(cmfErr);
            #endregion Err
            //dbsAnalysisClass.Namespace.GetNamespace().Types.Add(ctdReturnType);
            ctd1.Members.Add(ctdReturnType);
            #endregion
        }
    }
}
